#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;


int main()
{
 int N,Q,A,B,C;
 int S = 0;
 cin >> N;
 int oc[100001] = {0};
 for (int i=0; i<N; i++){
    cin >> A;
    oc[A]++;
    S += A;
 }
 cin >> Q;
 for (int j=0; j<Q; j++){
    cin >> B >> C;
    S += (C-B)*oc[B];
    oc[C] += oc[B];
    oc[B] = 0;
    cout << S << "\n";
 }
}

#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
using namespace std;


int main()
{
 int N,Q,A,B,C;
 int S = 0;
 cin >> N;
 int oc[100001] = {0};
 for (int i=0; i<N; i++){
    cin >> A;
    oc[A]++;
    S += A;
 }
 cin >> Q;
 for (int j=0; j<Q; j++){
    cin >> B >> C;
    S += (C-B)*oc[B];
    oc[C] += oc[B];
    oc[B] = 0;
    cout << S << "\n";
 }
}

