def resolve():
    N = int(input())
    A = input().split()
    Q = int(input())
    for _ in range(Q):
        b, c = input().split()
        for a in A:
        a.replace(b, c)
    print(sum(map(int, A)))

if __name__ == '__main__':
    resolve()