#include <iostream>
#include <string.h>
using namespace std;

int main() {
    int n;
    int a[200001];
    int vis[200001];
    memset(vis, 0, sizeof(vis));
    scanf("%d", &n);
    long long nSum = 0;
    for(int i=0; i<n; i++) {
        scanf("%d", &a[i]);
        vis[a[i]]++;
        nSum += a[i];
    }
    int q;
    scanf("%d", &q);
    for(int i=0; i<q; i++) {
        int x, y;
        scanf("%d %d", &x, &y);
        int nCount = vis[x];
        vis[y] += nCount;
        vis[x] = 0;
        nSum -= x * nCount;
        nSum += y * nCount;
        printf("%lld\n", nSum);
    } 
    return 0;
}