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