#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, d;
  cin >> n;
  long long int sum = 0;
  unordered_map<int, int> m;
  for (int i = 0; i < n; ++i) {
    cin >> d;
    ++m[d];
    sum += d;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum -= m[b] * b;
    m[c] += m[b];
    sum += m[b] * c;
    m[b] = 0;
    cout << sum << "\n";
  }
  return 0;
}
