#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define loop0(i,n) for(int i=0; i<(n); i++)
#define loop1(i,n) for(int i=1; i<=(n); i++)
#define fori(a,b,i) for(int i=(a); i<=(b); i++)
#define ford(a,b,i) for(int i=(a); i>=(b); i--)
#define fast_io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ign cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define INF 0x3f3f3f3f
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define endl "\n"
#define fir first
#define sec second
#define pb push_back
#define mp make_pair
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef map<int,int> MII;
typedef map<int,int> MCI;
typedef unordered_map<int,int> UMII;
typedef unordered_map<char,int> UMCI;
typedef set<int> SI;
typedef long long int llint;
int main() {
fast_io;
llint n;
cin >> n;
vector<llint> v(n);
unordered_map<llint, llint> m;
for(auto &i : v) cin >> i;
for (llint i = 0; i < n; i++) m[v[i]]++;
llint q;
cin >> q;
llint sum = accumulate(v.begin(), v.end(), 0);
for(llint i = 0; i < q; i++){
llint a,b;
cin >> a >> b ;
sum = sum - (1LL*a*m[a]) +(1LL*b*m[a]);
m[b] += m[a];
m[a] = 0;
cout << sum << endl;
}
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgZGVidWcoeCkgY291dCA8PCAnPicgPDwgI3ggPDwgJzonIDw8IHggPDwgZW5kbDsKI2RlZmluZSBsb29wMChpLG4pIGZvcihpbnQgaT0wOyBpPChuKTsgaSsrKQojZGVmaW5lIGxvb3AxKGksbikgZm9yKGludCBpPTE7IGk8PShuKTsgaSsrKQojZGVmaW5lIGZvcmkoYSxiLGkpIGZvcihpbnQgaT0oYSk7IGk8PShiKTsgaSsrKQojZGVm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