#include <iostream>
#include <vector>

using namespace std;

const int max = 100001;
int sum(const vector<int> &vec)
{
    int sum = 0;
    for (int i = 0; i < max; ++i)
    {
        sum += vec.at(i) * i;
    }
    return sum;
}

int main()
{
    vector<int> vec(max);

    int N, A;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> A;
        vec.at(A)++;
    }

    int Q, B, C;
    cin >> Q;
    for (int i = 0; i < Q; ++i)
    {
        cin >> B >> C;
        int &b = vec.at(B);
        int &c = vec.at(C);
        if (b > 0)
        {
            c += b;
            b = 0;
        }
        cout << sum(vec) << endl;
    }

    return 0;
}