import sys
T = int(sys.stdin.readline().rstrip())
for i in range(T):
    a, b = map(int, sys.stdin.readline().rstrip().split())
    if 1 <= a < 100 and 1 <= b < 1000000:
        data = a ** b
        num = data % 10
        print(num)
    else:
        break

43b9de0ba3d121908fc4300adfe9b3cc03872de3
<mask token>

<mask token>
for i in range(T):
    a, b = map(int, sys.stdin.readline().rstrip().split())
    if 1 <= a < 100 and 1 <= b < 1000000:
        data = a ** b
        num = data % 10
        print(num)
    else:
        break

<mask token>
T = int(sys.stdin.readline().rstrip())
for i in range(T):
    a, b = map(int, sys.stdin.readline().rstrip().split())
    if 1 <= a < 100 and 1 <= b < 1000000:
        data = a ** b
        num = data % 10
        print(num)
    else:
        break

import sys
T = int(sys.stdin.readline().rstrip())
for i in range(T):
    a, b = map(int, sys.stdin.readline().rstrip().split())
    if 1 <= a < 100 and 1 <= b < 1000000:
        data = a ** b
        num = data % 10
        print(num)
    else:
        break
