#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, Q;
  cin >> N;
  vector<int> a(N);
  vector<int> b(Q);
  vector<int> c(Q);
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    cin >> b[i];
    cin >> c[i];
  }
  vector<int> d(pow(10, 5) + 5, 0);
  ll s = 0;
  for (int i = 0; i < N; i++) {
    d[a[i] - 1]++;
    s += a[i];
  }
  for (int i = 0; i < Q; i++) {
    s += (c[i] - b[i]) * d[b[i] - 1];
    d[c[i] - 1] += d[b[i] - 1];
    d[b[i] - 1] -= d[b[i] - 1];
    cout << s << endl;
  }
}
