#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, a[100000], l, r, x;
  long long sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += x;
    a[x]++;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> l >> r;
    int v = a[l];
    sum = sum - (1ll * v * l) + (1ll * v * r);
    a[l] = 0;
    a[r] += v;
    cout << sum << endl;
  }
  return 0;
}
