#include <bits/stdc++.h>
using namespace std;
const int mod = 1e5 + 5;
int main() {
  int n;
  cin >> n;
  int a[n], there[mod] = {0};
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sum += a[i];
    there[a[i]]++;
  }
  int q;
  cin >> q;
  int b, c;
  while (q--) {
    cin >> b >> c;
    if (there[b] > 0) {
      sum += (there[b] * c);
      sum -= (there[b] * b);
      there[c] += there[b];
      there[b] = 0;
    }
    cout << sum << "\n";
  }
}
