#include <iostream>
#include <unordered_map>

using namespace std;

long long Sum(const unordered_map<int, int> &m)
{
    int sum = 0;
    for (const auto &pair : m)
    {
        sum += pair.first * pair.second;
    }
    return sum;
}

int main()
{
    unordered_map<int, int> mapnum;

    int N, A;
    cin >> N;
    for (int i = 0; i < N; ++i)
    {
        cin >> A;
        mapnum[A]++;
    }

    long long sum = Sum(mapnum);

    long long Q, B, C;
    cin >> Q;
    for (int i = 0; i < Q; ++i)
    {
        cin >> B >> C;
        if (mapnum.find(B) != mapnum.end())
        {
            long long &b = mapnum[B];
            long long &c = mapnum[C];

            c += b;
            sum -= B * b;
            sum += C * b;
            b = 0;
        }

        cout << sum << endl;
    }

    return 0;
}