 Timer is Running

Find (a^b)%m
##### Submissions: 2305   Accuracy: 30.12%   Difficulty: Easy   Marks: 2

Given three numbers a, b and m where 1<=b,m<=10^6 and ‘a’ may be very large and contains upto 10^6 digits. The task is to find (a^b)%m.

Examples:

```Input  : a = 3, b = 2, m = 4
Output : 1
Explanation : (3^2)%4 = 9%4 = 1

Input : a = 987584345091051645734583954832576, b = 3, m = 11
Output: 10```

Input:
The first line of input contains T denoting the no of test cases . Then T test cases follow . The first line of each test case contains 3  separated integers denoting a, b and m.

Output:
For each test case output the required result in a new line.

Constraints:
1<=T<=100
1<=b,m<=10^6

Example:
Input:

2
3 2 4
2 10 6
Output:
1
4

#### ** For More Input/Output Examples Use 'Expected Output' option **

Author: Shubham Joshi 1

If you have purchased any course from GeeksforGeeks then please ask your doubt on course discussion forum. You will get quick replies from GFG Moderators there.