#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q, max = 0, buf, buf_1, buf_2;
  cin >> n;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> buf;
    v.at(i) = buf;
    if (buf > max) max = buf;
  }
  vector<int> vv(max, 0);
  for (auto itr = v.begin(); itr != v.end(); itr++) {
    vv.at(*itr)++;
  }
  long int sum = accumulate(v.begin(), v.end(), 0);
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> buf_1 >> buf_2;
    sum = sum - vv.at(buf_1) * (buf_2 - buf_1);
    vv.at(buf_2) += vv.at(buf_1);
    vv.at(buf_1) = 0;
    cout << sum << endl;
  }
  return 0;
}
