n = int(input())
a = list(map(int,input().split()));
q = int(input())
aa = 0;
for i in range(n):
    aa += a[i];

b = [input().split() for l in range(q)]

bu = [0]*(100000);

for i in range(100000):
    bu[i] = a.count(i);
    
for x in range(q):
    c = int(b[x][0])
    d = int(b[x][1])
    aa += (d-c)*(bu[c]);
    bu[d] += bu[c];
    bu[c] = 0;
    print(aa);