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