#!/usr/bin/env python3

def main():
    from collections import Counter

    N = int(input())
    A = list(map(int, input().split()))
    Q = int(input())

    A_Counter = Counter(A)
    for i in range(Q):
        B, C = map(int, input().split())
        A_Counter[C] += A_Counter[B]
        A_Counter[B] = 0

        print(sum(A_Counter.elements()))


if __name__ == "__main__":
    main()
