import sys

import itertools

sys.setrecursionlimit(1000000000)

from heapq import heapify,heappop,heappush,heappushpop

import math

import collections

import copy



if __name__ == "__main__":

    n = int(eval(input()))

    a = list(map(int,input().split()))

    q = int(eval(input()))

    cnt = [0]*(10**5+7)

    for i in range(n):

        cnt[a[i]]+=1

    ruiseki = sum(a)

    for i in range(q):

        b,c = list(map(int,input().split()))

        d = cnt[b]

        e = d*(c-b)

        cnt[c] += d

        cnt[b] -= d

        ruiseki += e

        print(ruiseki)
import sys

import itertools

sys.setrecursionlimit(1000000000)

from heapq import heapify,heappop,heappush,heappushpop

import math

import collections

import copy



def main():

    n = int(eval(input()))

    a = list(map(int,input().split()))

    q = int(eval(input()))

    cnt = [0]*(10**5+7)

    for i in range(n):

        cnt[a[i]]+=1

    p = sum(a)

    for i in range(q):

        b,c = list(map(int,input().split()))

        d = cnt[b]

        e = cnt[c]

        diff = d*(c-b)

        p += diff

        cnt[c]+=d

        cnt[b]-=d

        print(p)

if __name__ == "__main__":

    main()
import sys
import itertools

sys.setrecursionlimit(1000000000)
from heapq import heapify, heappop, heappush, heappushpop
import math
import collections
import copy

if __name__ == "__main__":
    n = int(eval(input()))
    a = list(map(int, input().split()))
    q = int(eval(input()))
    cnt = [0] * (10**5 + 7)
    for i in range(n):
        cnt[a[i]] += 1
    ruiseki = sum(a)
    for i in range(q):
        b, c = list(map(int, input().split()))
        d = cnt[b]
        e = d * (c - b)
        cnt[c] += d
        cnt[b] -= d
        ruiseki += e
        print(ruiseki)

import sys
import itertools

sys.setrecursionlimit(1000000000)
from heapq import heapify, heappop, heappush, heappushpop
import math
import collections
import copy


def main():
    n = int(eval(input()))
    a = list(map(int, input().split()))
    q = int(eval(input()))
    cnt = [0] * (10**5 + 7)
    for i in range(n):
        cnt[a[i]] += 1
    p = sum(a)
    for i in range(q):
        b, c = list(map(int, input().split()))
        d = cnt[b]
        e = cnt[c]
        diff = d * (c - b)
        p += diff
        cnt[c] += d
        cnt[b] -= d
        print(p)


if __name__ == "__main__":
    main()

-if __name__ == "__main__": + +def main(): -    ruiseki = sum(a) +    p = sum(a) -        e = d * (c - b) +        e = cnt[c] +        diff = d * (c - b) +        p += diff -        ruiseki += e -        print(ruiseki) +        print(p) + + +if __name__ == "__main__": +    main()