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 math \n\ndef no(n):\n    c=0\n    while n>0:\n        c += 1\n        n //=10\n    return c\n\n  \n# Function to find modulo inverse of b. It returns  \n# -1 when inverse doesn't  \n# modInverse works for prime m \ndef modInverse(a, m) : \n    m0 = m \n    y = 0\n    x = 1\n  \n    if (m == 1) : \n        return 0\n  \n    while (a > 1) : \n  \n        # q is quotient \n        q = a // m \n  \n        t = m \n  \n        # m is remainder now, process \n        # same as Euclid's algo \n        m = a % m \n        a = t \n        t = y \n  \n        # Update x and y \n        y = x - q * y \n        x = t \n  \n  \n    # Make x positive \n    if (x < 0) : \n        x = x + m0 \n  \n    return x \n  \n  \n# Function to compute a/b under modulo m  \n \n\n\nfor _ in range(int(input())):\n    a,n,m = map(int,input().split(' '))\n    s = no(a)   \n    c = 10**s - 1\n    if math.gcd(c,m) == 1:\n        b = pow(10,n*s,m)-1\n        r = modInverse(c,m)\n        d = (b%m)*(r%m)\n    else:\n        w = c*m\n        b = pow(10,n*s,w)-1\n        d = b//c\n    ans = (d%m)*(a%m)\n    print(ans%m)  \n  \n        \n    "
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13477