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