#include <bits/stdc++.h>
using namespace std;
int main() {
  int s = 0;
  int n, tmp;
  int a[100001];
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> tmp;
    ++a[tmp];
    s += tmp;
  }
  int q;
  cin >> q;
  int b, c;
  for (int i = 0; i < q; ++i) {
    cin >> b >> c;
    s += a[c] * c - a[b] * b;
    --a[b];
    ++a[c];
    cout << s << endl;
  }
  return 0;
}
