#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  int sum = 0;
  map<int, int> dic;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    dic[tmp]++;
    sum += tmp;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    auto it = dic.find(b);
    if (it != dic.end()) {
      sum += (c - b) * it->second;
      dic[c] += it->second;
      dic[b] = 0;
    }
    printf("%d\n", sum);
  }
}
