#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int ar[n];
  for (int i = 0; i < n; i++) cin >> ar[i];
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    m[ar[i]]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int a, b;
    cin >> a >> b;
    int cnt = m[a];
    m.erase(a);
    m[b] += cnt;
    int sum = 0;
    for (auto x : m) {
      sum += (x.first) * (x.second);
    }
    cout << sum << endl;
  }
}
