#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  std::vector<int> a(n);
  map<int, int> m;
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    if (m.find(b) != m.end()) {
      m[c] += m[b];
      sum -= b * m[b];
      sum += c * m[b];
      m.erase(m.find(b));
    }
    cout << sum;
    cout << endl;
  }
  return 0;
}
