#!/usr/bin/env python3
def main():
    _ = int(input())
    A = [int(x) for x in input().split()]
    Q = int(input())

    for _ in range(Q):
        B, C = map(int, input().split())
        res = []
        ans = 0
        for a in A:
            res.append(a if a != B else C)
            ans += res[-1]
        print(ans)
        A = list(res)


if __name__ == '__main__':
    main()
