#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> seq_a(10001, 0);
  int64_t sum_a = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    seq_a.at(x)++;
    sum_a += x;
  }
  int q;
  cin >> q;
  vector<int64_t> answer(q, 0);
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    sum_a += (c - b) * seq_a.at(b);
    seq_a.at(c) += seq_a.at(b);
    seq_a.at(b) = 0;
    answer.at(i) = sum_a;
  }
  for (int64_t ans : answer) {
    cout << ans << endl;
  }
}
