#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  long long s = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; i++) cin >> b[i] >> c[i];
  short p[100000];
  for (int i = 0; i < n; i++) {
    s += a[i];
    p[a[i]] += 1;
  }
  for (int i = 0; i < q; i++) {
    s += (c[i] - b[i]) * p[b[i]];
    p[c[i]] += p[b[i]];
    p[b[i]] = 0;
    cout << s << endl;
  }
  return 0;
}
