N = int(input())
given_list = [int(i) for i in input().split()]
Q = int(input())

for _ in range(Q):
    B, C = map(int, input().split())

    if B in given_list:
        for i in range(N):
          if given_list[i] == B:
              given_list[i] = C
        print(sum(given_list)) #####       
    else:  
        print(sum(given_list)) #####