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