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