#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t;
  cin >> t;
  long long int a[t];
  map<long long int, long long int> mpp;
  long long int sum = 0;
  for (int i = 0; i < t; i++) {
    cin >> a[i];
    mpp[a[i]]++;
    sum += a[i];
  }
  long long int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long int aa, b;
    cin >> aa >> b;
    sum = sum - (mpp[aa] * aa) + mpp[aa] * b;
    cout << sum << "\n";
    mpp[b] += mpp[aa];
  }
}
