import java util Scanner public class Task045 public static void main

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import java.util.Scanner;
public class Task045 {
public static void main(String[] args) {
Scanner scanner = new Scanner (System.in);
int n = scanner.nextInt();
String [] a = new String[n];
for (int i = 0; i < n; i++) {
a[i] = scanner.next();
}
int [] a1 = new int [n];
for (int i = 0; i < n; i++) {
a1[i] = 0;
}
int k = scanner.nextInt();
while (k > 0) {
String s = scanner.nextLine();
String [] b = s.split(" ");
for (int i = 0; i < n; i++) {
if (a[i] == b[0]) {
a1[i] = a1[i] + b[2].charAt(0) - b[2].charAt(2);
}
if (a[i] == b[1]) {
a1[i] = a1[i] + b[2].charAt(2) - b[2].charAt(0);
}
}
k--;
}
for (int i = 0; i < n; i++) {
System.out.println(a[i] + " " + a1[i]);
}
}
}