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