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