import strutils, sequtils, math
var
    n = stdin.readLine.parseInt
    a = map(stdin.readLine.split, parseInt)
    q = stdin.readLine.parseInt
    bc: seq[int]
for i in 0..<q:
    bc = map(stdin.readLine.split, parseInt)
    for j in 0..<n:
        if a[j] == bc[0]:
            a[j] = bc[1]
    echo sum(a)