#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	D_fix
# CreatedDate:  2020-06-21 22:17:03 +0900
# LastModified: 2020-06-21 22:25:13 +0900
#




def main():
    n = int(input())
    a = list(map(int, input().split()))
    cnt = [0]*100001
    for s in a:
        cnt[s]+=1
    q = int(input())
    for _ in range(q):
        b, c = map(int, input().split())
        spare = cnt[b]
        cnt[b] = 0
        cnt[c] += spare
        print(sum(i*cnt[i] for i in range(len(cnt))))



if __name__ == "__main__":
    main()
