#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a < b) swap(a, b);
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t, n, q, a, b;
  cin >> n;
  vector<int> V(100000, 0);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> t;
    sum += t;
    V[t]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> a >> b;
    sum += (b - a) * (V[a]);
    V[a] = 0;
    V[b] += a;
    cout << sum << "\n";
  }
  return 0;
}
