Eugene has to do his homework. But today, he is feeling very lazy and wants to you do his homework. His homework has the following given maths problem.
You are given three integers: A, N, M. You write the number A appended to itself N times in a row. Let's call the resulting big number X. For example, if A = 120, N = 3, then X will be 120120120. Find out the value of X modulo M.

-----Input-----
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follow.
Each test case is described in one line containing three integers: A, N and M as described in the problem statement.

-----Output-----
For each test case, output a single line containing an integer denoting the value of X modulo M.

-----Constraints-----
- 1 ≤ T ≤ 105
- 0 ≤ A ≤ 109
- 1 ≤ N ≤ 1012
- 2 ≤ M ≤ 109

-----Subtasks-----
Subtask #1 (15 points):
- 0 ≤ A ≤ 100
- 1 ≤ N ≤ 105

Subtask #2 (25 points):
- 1 ≤ N ≤ 109

Subtask #3 (60 points):
- Original constraints

-----Example-----
Input:
2
12 2 17
523 3 11

Output:
5
6

-----Explanation-----
Example 1: As A = 12, N = 2, X = 1212, 1212 modulo 17 = 5
Example 2. As A = 523, N = 3, X = 523523523, 523523523 modulo 11 = 6

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'import sys\r\ndef cal_power(a, n, m):\r\n    if n == 0:\r\n        return 1\r\n    elif n == 1:\r\n        return a % m\r\n    elif not n % 2:\r\n        return ((cal_power(a, n // 2, m) % m)**2) % m\r\n    else:\r\n        return ((a % m) * (((cal_power(a, (n - 1)// 2, m)) % m)**2) % m) % m\r\n\r\ndef cal(b, n, m):\r\n    if n == 0:\r\n        return 0\r\n    elif n == 1:\r\n        return b % m\r\n    elif not n % 2:\r\n        return (((1 +cal_power(b, n // 2, m)) % m) * (cal(b, n // 2, m) % m)) % m\r\n    else:\r\n        return (((1 + cal_power(b, (n + 1) // 2, m)) % m) * (cal(b, ((n - 1) // 2), m) % m) + cal_power(b, (n + 1) // 2, m) % m) % m\r\n\r\ndef solve(a, n, m):\r\n    l = len(str(a))\r\n    x = a % m\r\n    q = 10**l % m\r\n    return (x * (1 + cal(q, n - 1, m))) % m\r\n\r\nfor _ in range(int(input())):\r\n    a,n,m = [int(temp) for temp in input().split()]\r\n    print(solve(a, n, m))'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13411