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