F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Guess the Money

Time 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
3 2 0 1 1 0 9 1 0 1 1 0 5 1 0 1 0 2 0 3 0 2 0
 

Sample Output
Case #1: 9 Case #2: 6 Case #3: IMPOSSIBLE
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-07-05 23:34:04, Gzip enabled