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