Dshawn is a tuhao. He has a lot of money. One day, he gave A dollars to kuangbin and cxlove. kuangbin got B dollars and cxlove got C dollars. Obviously, A = B + C.
wuyiqi is very curious, he want to know the A,B and C. But they didn’t tell him. Just tell him some information about the three numbers.
Dshawn said that the number A has N
1 digits in its decimal representation (without extra leading zero). Assume the digits of its decimal expansion from the left to the right are a
0, a
1, ..., a
N1 - 1. Dshawn didn’t tell wuyiqi all the digits but tell him M
1 digits.
kuangbin said that the number B has N
2 digits in its decimal representation (without extra leading zero). Assume the digits of its decimal expansion from the left to the right are b
0, b
1, ..., b
N2 - 1. kuangbin didn’t tell wuyiqi all the digits but tell him M
2 digits.
cxlove said that the number C has N
3 digits in its decimal representation (without extra leading zero). Assume the digits of its decimal expansion from the left to the right are c
0, c
1, ..., c
N3 - 1. cxlove didn’t tell wuyiqi all the digits but tell him M
3 digits.
You should find the number of possible {A, B, C}. It is possible that someone tells lies, so if the information given is inconsistent with any possible {A, B, C}, you should also detect this.
The first line of the input is T (1 ≤ T ≤ 50), which stands for the number of test cases you need to solve.
The first line of each case contains two integers N
1,M
1 (1 ≤ N
1 ≤ 10
7, 0 ≤ M
1 ≤ min(N
1, 10
4)).
For the next M
1 lines, each line contains two integers id and x (0 ≤ id < N
1, 0 ≤ x ≤ 9) means a
id = x.
The next line contains two integers N
2,M
2 (1 ≤ N
2 ≤ 10
7, 0 ≤ M
2 ≤ min(N
2, 10
4)).
For the next M
2 lines, each line contains two integers id and x (0 ≤ id < N
2, 0 ≤ x ≤ 9) means b
id = x.
The next line contains two integers N
3,M
3 (1 ≤ N
3 ≤ 10
7, 0 ≤ M
3 ≤ min(N
3, 10
4)).
For the next M
3 lines, each line contains two integers id and x (0 ≤ id < N
3, 0 ≤ x ≤ 9) means c
id = x.
For each test case, print a line “Case #t: ”(without quotes, t means the index of the test case) at the beginning.
If it is impossible, please output “IMPOSSIBLE” else output the answer modulo 20140927.