#include <bits/stdc++.h>
using namespace std;
int solve() { return 0; }
int v[1000000] = {0};
int main() {
  long long n;
  int k, sum = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> k;
    sum += k;
    v[k]++;
  }
  long long t;
  long long y, u;
  cin >> t;
  while (t--) {
    cin >> u >> y;
    sum -= u * v[u];
    sum += y * v[u];
    cout << sum << endl;
    v[y] += v[u];
    v[u] = 0;
  }
  return 0;
}
