|
||||||||||
Guess the MoneyTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 166 Accepted Submission(s): 46 Problem Description 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 N1 digits in its decimal representation (without extra leading zero). Assume the digits of its decimal expansion from the left to the right are a0, a1, ..., aN1 - 1. Dshawn didn¡¯t tell wuyiqi all the digits but tell him M1 digits. kuangbin said that the number B has N2 digits in its decimal representation (without extra leading zero). Assume the digits of its decimal expansion from the left to the right are b0, b1, ..., bN2 - 1. kuangbin didn¡¯t tell wuyiqi all the digits but tell him M2 digits. cxlove said that the number C has N3 digits in its decimal representation (without extra leading zero). Assume the digits of its decimal expansion from the left to the right are c0, c1, ..., cN3 - 1. cxlove didn¡¯t tell wuyiqi all the digits but tell him M3 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. Input 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 N1,M1 (1 ¡Ü N1 ¡Ü 107, 0 ¡Ü M1 ¡Ü min(N1, 104)). For the next M1 lines, each line contains two integers id and x (0 ¡Ü id < N1, 0 ¡Ü x ¡Ü 9) means aid = x. The next line contains two integers N2,M2 (1 ¡Ü N2 ¡Ü 107, 0 ¡Ü M2 ¡Ü min(N2, 104)). For the next M2 lines, each line contains two integers id and x (0 ¡Ü id < N2, 0 ¡Ü x ¡Ü 9) means bid = x. The next line contains two integers N3,M3 (1 ¡Ü N3 ¡Ü 107, 0 ¡Ü M3 ¡Ü min(N3, 104)). For the next M3 lines, each line contains two integers id and x (0 ¡Ü id < N3, 0 ¡Ü x ¡Ü 9) means cid = x. Output 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. Sample Input
Sample Output
Source | ||||||||||
|