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