#include <algorithm>
#include <iostream>
#include <vector>
#include <numeric>
#include <string>
#include <stdio.h>
#include <set>
#include <iomanip>
using namespace std;
 
 
int main(){
    int N, Q;
    cin >> N;
    long long sum, M;
    vector<long long> A(N);
    for (int i=0; i<N; i++){
        cin >> A[i];
    }
    vector<long long> B(Q);
    vector<long long> C(Q);
    cin >> Q;
    for (int i=0; i<Q; i++){
        cin >> B[i] >> C[i];
    }
    sum = accumulate(A.begin(), A.end(), 0);
    for (int j=0; j<Q; j++){
        M = count(A.begin(), A.end(), B[j]);
        replace(A.begin(), A.end(), B[j], C[j]);
        sum = sum + M * (C[j] - B[j]);
        cout << sum << endl;
    }
    return 0;
}