#arc176b. B - Simple Math 4

B - Simple Math 4

Score : 400400 points

问题陈述

2N2^N 除以 2M2K2^M - 2^K 时,找出余数的最后一位数字。

你将得到 TT 个测试用例,每个都必须解决。

以上为大语言模型 kimi 翻译,仅供参考。

Problem Statement

Find the last digit of the remainder when 2N2^N is divided by 2M2K2^M - 2^K.

You are given TT test cases, each of which must be solved.

Constraints

  • 1T2×1051 \le T \le 2 \times 10^5
  • 1N10181 \le N \le 10^{18}
  • 1K<M10181 \le K < M \le 10^{18}
  • N,M,KN,M,K are integers.

Input

The input is given from Standard Input in the following format, where casei\mathrm{case}_i represents the ii-th test case:

TT

case1\mathrm{case}_1

case2\mathrm{case}_2

\vdots

caseT\mathrm{case}_T

Each test case is given in the following format:

NN MM KK

Output

Print the answer.

Sample Input 1

5
9 6 2
123 84 50
95 127 79
1000000007 998244353 924844033
473234053352300580 254411431220543632 62658522328486675

Sample Output 1

2
8
8
8
4

For the first test case, the remainder of 292^9 divided by 26222^6 - 2^2 is 3232. Thus, the answer is the last digit of 3232, which is 22.