#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  int hash[100001] = {0};
  int A[n];
  int s = 0;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    s += A[i];
    hash[A[i]]++;
  }
  int q;
  cin >> q;
  while (q > 0) {
    int x, y;
    cin >> x >> y;
    if (hash[x] != 0) {
      hash[y] += hash[x];
      s = s + ((y - x) * (hash[x]));
      cout << s << endl;
      hash[x] = 0;
    } else
      cout << s << endl;
    q--;
  }
  return 0;
}
