#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n;
  cin >> n;
  long long int arr[n];
  long long int sum = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    m[arr[i]]++;
  }
  long long int q;
  cin >> q;
  while (q--) {
    sum = 0;
    long long int a, b;
    cin >> a >> b;
    m[b] = m[b] + m[a];
    m[a] = 0;
    for (auto it = m.begin(); it != m.end(); it++) {
      sum = sum + (it->second) * (it->first);
    }
    cout << sum << endl;
  }
}
