#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(100001, 0);
  long long sum = 0;
  for (int i = 1; i <= n; ++i) {
    int temp;
    cin >> temp;
    sum += temp;
    v[temp]++;
  }
  int q;
  cin >> q;
  int b, c;
  while (q--) {
    cin >> b >> c;
    sum -= (v[b] * b);
    sum += (v[b] * c);
    v[c] += v[b];
    v[b] = 0;
    cout << sum << endl;
  }
}
