#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> memo;
  for (int i = 0; i < n; i++) {
    int value;
    cin >> value;
    if (memo.find(value) != memo.end()) {
      memo[value]++;
    } else {
      memo[value] = 1;
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (memo.find(c) == memo.end()) {
      memo[c] = 0;
    }
    if (memo.find(b) != memo.end()) {
      memo[c] += memo[b];
      memo[b] = 0;
    }
    long long sum = 0;
    for (auto const& [value, fre] : memo) {
      sum += value * fre;
    }
    cout << sum << endl;
  }
}
