#include <bits/stdc++.h>
using namespace std;
int main() {
  map<int, int> m;
  map<int, int>::iterator it;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    m[temp]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    int temp = m[x];
    m[x] = 0;
    m[y] += temp;
    int sum = 0;
    for (it = m.begin(); it != m.end(); it++) {
      sum += (it->first) * (it->second);
    }
    cout << sum << endl;
  }
}
