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