#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define SIZE 100002
typedef long long ll;
ll main(){
    ll table[SIZE]={0},sum=0;
    ll N;
    scanf("%d",&N);
    ll A[SIZE];
    for(ll i=0;i<N;i++){
        scanf("%d",A+i);
        table[A[i]]++;
        sum += A[i];
    }
    ll Q;
    scanf("%d",&Q);
    ll B[SIZE],C[SIZE];
    for(ll i=0;i<Q;i++)
        scanf("%d %d",B+i,C+i);
    for(ll i=0;i<Q;i++){
        sum += table[B[i]] * (C[i] - B[i]);
        printf("%lld\n",sum);
        table[C[i]] += table[B[i]];
        table[B[i]] = 0;
    }
}
