#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int te = 1;
  while (te--) {
    long long a, k, c, n, rem, ans = 0LL, q, b;
    cin >> n;
    unordered_map<int, int> um;
    for (int i = 1; i <= n; i++) {
      cin >> a;
      ans += a;
      if (um.find(a) == um.end())
        um[a] = 1;
      else
        um[a]++;
    }
    cin >> q;
    for (int i = 1; i <= q; i++) {
      cin >> b >> c;
      ans = ans - um[b] * b + um[b] * c;
      if (um.find(c) == um.end())
        um[c] = um[b];
      else
        um[c] += um[b];
      cout << ans << endl;
    }
  }
  return 0;
}
