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