#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  unordered_map<int, int> m;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    m[d]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int x = m[b];
    m[b] = 0;
    m[c] += x;
    int ans = 0;
    for (auto i : m) {
      ans += i.first * i.second;
    }
    cout << ans << endl;
  }
  return 0;
}
