#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> note;
  int sum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    note[a]++;
    sum += a;
  }
  int q_count;
  cin >> q_count;
  for (int i = 0; i < q_count; i++) {
    int b, c;
    cin >> b >> c;
    note[c] += note[b];
    sum += (c - b) * note[b];
    note[b] = 0;
    cout << sum << endl;
  }
}
