#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m, q;
  cin >> n;
  vector<int> qw(100000);
  q = 0;
  for (int i = 0; i < n; ++i) {
    int f;
    cin >> f;
    qw[f - 1] += 1;
    q += f;
  }
  cin >> m;
  for (int i = 0; i < m; ++i) {
    int f, d;
    cin >> f >> d;
    q -= qw[f - 1] * f;
    q += qw[f - 1] * d;
    qw[d - 1] += qw[f - 1];
    qw[f - 1] = 0;
    cout << q << endl;
  }
}
