#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long long sum = 0;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    m[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b1, b2;
    cin >> b1 >> b2;
    sum -= m[b1] * b1;
    sum += m[b1] * b2;
    m[b2] += m[b1];
    m[b1] = 0;
    cout << sum << "\n";
  }
  return 0;
}
