#include <bits/stdc++.h>
using namespace std;
const int width = 100001;
int main() {
  int n;
  cin >> n;
  vector<int> ans(width, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    ans.at(a)++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (ans.at(b) > 0) {
      ans.at(c) += ans.at(b);
      ans.at(b) = 0;
    }
    long long answer = 0;
    for (int i = 1; i < width; i++) {
      answer += i * ans.at(i);
    }
    cout << answer << endl;
  }
}
