def my_index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

def main():
    n = int(input())
    a_list = [int(_) for _ in input().split()]
    Q = int(input())

    s_list = []
    for q in range(Q):
        b, c = map(int, input().split())
        a_index_list = my_index_multi(a_list, b)
        
        for i in a_index_list:
            a_list[i] = c

        s_list.append(sum(a_list))

    for s in s_list:
        print(s)

main()