#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int output = 0;
  vector<int> num(100000, 0);
  for (int i = 0; i < n; i++) {
    int l;
    cin >> l;
    num.at(l - 1)++;
    output += l;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int bef = 0;
    int aft = 0;
    cin >> bef >> aft;
    output += num.at(bef - 1) * (aft - bef);
    num.at(aft - 1) += num.at(bef - 1);
    num.at(bef - 1) = 0;
    cout << output << endl;
  }
  cout << endl;
}
