#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using namespace std;
void YesNo(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YESNO(bool b) { cout << (b ? "YES" : "NO") << endl; }
long long N;
long long Q;
long long sum = 0;
long long pool[100010];
signed main() {
  cin >> N;
  for (long long(i) = 0; (i) < (N); (i)++) {
    long long a;
    cin >> a;
    pool[a]++;
    sum += a;
  }
  cin >> Q;
  for (long long(q) = 0; (q) < (Q); (q)++) {
    long long b, c;
    cin >> b >> c;
    long long cnt = pool[b];
    sum -= cnt * b;
    sum += cnt * c;
    pool[c] += cnt;
    cout << sum << endl;
  }
}
