#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long freq[N];
void doit() {
  long long n, m, i, j, k, c, ans = 0, x;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    freq[x]++;
    ans += x;
  }
  long long q;
  cin >> q;
  while (q--) {
    long long c1, c2;
    cin >> c1 >> c2;
    k = freq[c1];
    c1 = freq[c1] * c1;
    freq[c1] = 0;
    ans -= c1;
    ans += c2 * k;
    freq[c2] += k;
    cout << ans << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    doit();
  }
}
