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