def main():
    n = int(input())
    a = list(map(int, input().split()))
    q = int(input())
    for _ in range(q):
        b, c = map(int, input().split())
        ichi = [x for x, i in enumerate(a) if i == b]
        for ie in ichi:
            a[ie] = c
        print(sum(a))

if __name__ == '__main__':
    main()
