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