#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Vi = vector<int>;
const int MAX = 100001;
int main() {
  int n;
  cin >> n;
  Vi a(n);
  vector<int> num_cnt(MAX, 0);
  long long sum = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a.at(i);
    sum += a.at(i);
    num_cnt.at(a.at(i))++;
  }
  int q;
  cin >> q;
  Vi b(q), c(q), s(q);
  for (int i = 0; i < (q); ++i) {
    cin >> b.at(i) >> c.at(i);
    sum += (c.at(i) - b.at(i)) * num_cnt.at(b.at(i));
    num_cnt.at(c.at(i)) += num_cnt.at(b.at(i));
    num_cnt.at(b.at(i)) = 0;
    s.at(i) = sum;
  }
  for (int i = 0; i < (q); ++i) {
    cout << s.at(i) << endl;
  }
  return 0;
}
