
#include <bits/stdc++.h>
using namespace std;

void c_p_c()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

bool sortKhela(const pair< int, int > &a,
               const pair< int, int > & b)
{
    return (a.first < b.first);
}

int main()
{
    c_p_c();
    int n;
    cin >> n;
    int arr[n];
    long 
    for (int i = 0; i < n; i++) cin >> arr[i];

    int m;
    cin >> m;
    long long sum;
    while (m--) {
        sum = 0;
        int from, to;
        cin >> from >> to;
        for (int i = 0; i < n; i++) {
            if (arr[i] == from) {
                arr[i] = to;
            }
            sum += arr[i];
        }
        cout << sum << endl;
    }
    return 0;
}