#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int lastindex = 0;
  int keep[100001] = {0};
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    if (x > lastindex) lastindex = x;
    keep[x]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    if (c > lastindex) lastindex = c;
    keep[c] += keep[b];
    keep[b] = 0;
    int sum = 0;
    for (int i = 1; i <= lastindex; i++) {
      sum += (i * keep[i]);
    }
    cout << sum << "\n";
  }
  return 0;
}
