#include <bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef unsigned long long int ull;
 
typedef vector <int> vi;
typedef vector <ll> vll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
 
typedef vector < pii > vpii;
typedef vector < pll > vpll;
 
typedef vector <string> vs;
typedef vector < vi > vvi;
typedef vector < vll > vvll;
 
#define fl(i, a, b)    for (int i(a); i <= (b); i ++)
#define rep(i, n)        fl (i, 1, (n))
#define loop(i, n)        fl (i, 0, (n) - 1)
#define rfl(i, a, b)    for (int i(a); i >= (b); i --)
#define rrep(i, n)        rfl (i, (n), 1)
 
#define all(v)     (v).begin(), (v).end()
#define srt(v)    sort (all (v))
 
#define pb push_back
#define mp make_pair
 
#define sz(x) ((int) (x).size())
#define fill (x, y)    memset(x, y, sizeof(x))
#define clr(a)    fill(a, 0)
// #define endl '\n'
 
#define PI 3.14159265358979323
 
const int Maxn = 1e6 + 1;
const int Mod = 1e9 + 7;
 
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
 
const ll MOD = 1000000007LL;
const ll MAX = 100010LL;
 
template <typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b);}
template <typename T> T power(T x, T y, ll m = MOD) { T ans = 1; x %= m; while (y > 0) { if (y & 1ll) ans = (ans * x) % m; y >>= 1ll; x = (x * x)%m; } return ans%m;}
 
template<typename T, typename T1>
T mod(T x, T1 p) {
    x %= p;
    if (x < 0)
        x += p;
    return x;
}
 
void leastPrimeFactor(vector<int>&least_prime, int n) 
{ 
    least_prime[1] = 1;  
    for (int i = 2; i <= n; i++) 
    { 
        if (least_prime[i] == 0) 
        { 
            least_prime[i] = i; 
            for (int j = 2*i; j <= n; j += i) 
                if (least_prime[j] == 0) 
                   least_prime[j] = i; 
        } 
    } 
}
 
 
// int inv[Maxn], ifact[Maxn], fact[Maxn];
// template<typename T>
// T inverse(T x, T p) 
// {
//     x = mod(x, p);
//     if (x == 1)
//         return x;
//     return mod((1LL * (-p / x) * (inv[p % x] % p)) , p); 
//     // Since inverse of p % x is already calculated.
// }
 
 
// ll NcR(ll n, ll r) 
// {
//     int ret = (1LL * ifact[n - r] * ifact[r]) % Mod ;
//  ret = (1LL * ret * fact[n]) % Mod;
//     return ret;
// }
 
 
// int n, t[4*MAXN];
// void build(int a[], int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = t[v*2] + t[v*2+1];
//     }
// }
// int sum(int v, int tl, int tr, int l, int r) {
//     if (l > r) 
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return sum(v*2, tl, tm, l, min(r, tm))
//            + sum(v*2+1, tm+1, tr, max(l, tm+1), r);
// }
// void update(int v, int tl, int tr, int pos, int new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = t[v*2] + t[v*2+1];
//     }
// }


int main() 
{
    FAST_IO;
    // int t;
    // cin >> t;
    // // dir = {{-1,0},{1,0},{0,1},{0,-1}};
    // for(int ze = 0 ; ze < t ; ze++)
    // {
    
    ll n;
    cin >> n;
    vector<ll> a(n);
    map<ll, ll> mp;
    ll sum = 0;
    for(ll i = 0 ; i < n ; i++)
    {
        cin >> a[i];
        sum+=a[i];
        if(mp.find(a[i])==mp.end())
            mp[a[i]] = 1;
        else
            mp[a[i]]++;
    }
    ll q,b,c;
    cin >> q;
    // cout << q << endl;
    while(q--)
    {
        cin >> b >> c;
        if(mp.find(b)!=mp.end())
        {
            sum-=(mp[b]*b);
            sum+=(mp[b]*c);
            if(mp.find(c)==mp.end())
                mp[c] = mp[b];
            else
                mp[c]+=mp[b];   
            mp.erase(mp.find(b));
        }
        cout << sum << endl;
    }
    // }
}

//1000000000000001


Measured memory_bytes: 7860