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