#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  long sum = 0;
  vector<int> a(100000);
  for (int i = 0; i < (int)(n); i++) {
    int tmp;
    cin >> tmp;
    a.at(tmp)++;
    sum += tmp;
  }
  int q;
  cin >> q;
  for (int i = 0; i < (int)(q); i++) {
    int b, c;
    cin >> b >> c;
    int cnt = a.at(b);
    sum = sum + cnt * (c - b);
    cout << sum << endl;
    a.at(c) += a.at(b);
    a.at(b) = 0;
  }
}
