/***********************************************
 *                                             *
 *   author: raghav_0901 (Raghav Dalmia)       *
 *   updated on: 21-06-2020, 10:23:12 pm IST   *
 *                                             *
\***********************************************/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

signed main( )
{
    int n, q;
    cin >> n;

    map<int, int> mp;

    int sum = 0, num;

    for (int i = 0; i < n; i++)
    {
        cin >> num;
        sum += num;
        mp[num]++;
    }

    cin >> q;

    while (q--)
    {
        int b, c;
        cin >> b >> c;
        if (mp.find(b) != mp.end( ))
        {
            int cnt = mp[b];
            mp.erase(b);
            sum -= (cnt * b);
            sum += (cnt * c);
            if (mp.find(c) != mp.end( ))
                mp[c] = mp[c] + cnt;
            else
                mp[c] = cnt;
            // for (auto it : mp) cout << it.first << " " << it.second << " ";
            // cout << endl;
        }
        cout << sum << endl;
    }

    return 0;
}
