LearnToCP
Sign in
Navigation
HomeRoadmapProblemsAbout Us
Theory
Basics
Your First ProgramData types and IOC++ syntaxModuloFunctionsVectorsMatricesTime Complexity
Sorting
SortingCounting sortRadix Sort
Optimization Techniques
Two PointersSum of numbers 1 to nPrefix sumBinary SearchGreedyBinary Search Functions
Binary Numbers
Binary NumbersNumbers in codeBitwise Operations
Math
Binary ExponentiationPrime NumbersPrime FactorizationGCD and LCMSieve of Eratosthenes
Data Structures
StringsStackQueue
Dynamic Programming
About DPDP problems

Last Digits of a Power

EasyProblem #31
Time LimitMemoryInputOutput
1 s64 MBstdinstdout

Print exactly k digits - watch the leading zeros.

For given positive integers a, n and k, your task is to print the last k digits of the power an.

Input

First line of input will be a single integer t - the number of testcases.
Each of the next t lines contains three integers a, n and k.

Output

For every testcase print a single line with exactly k characters - the last (rightmost) k digits of an, including leading zeros.

Example

Input
3
2 13 3
10 5 3
3452 20 4
Output
192
000
0576

213=8192, so its last three digits are 192. 105=100000 ends in three zeros - all three must be printed.

Constraints

1≤t≤105
1≤a,n≤109
1≤k≤9


This problem was adapted, with permission, from Poslednjih k cifara stepena, authored by Društvo matematičara Srbije and Fondacija Petlja.

Submit your solution

Sign in to submit your solution and track your progress.

Sign in to submit