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