#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  int A[n], tot = 0;
  map<int, int> P;
  for (int i = 0; i < n; ++i) {
    cin >> A[i];
    tot += A[i];
    P[A[i]]++;
  }
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int I, D;
    cin >> I >> D;
    int temp = tot;
    P[D] = P[I] + P[D];
    temp += (D - I) * P[I];
    P[I] = 0;
    tot = temp;
    cout << temp << endl;
  }
}
