#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  cin >> n;
  map<int, int> m;
  unsigned long long oldsum = 0;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    if (m.count(a) == 0) {
      m[a] = 1;
    } else {
      m.at(a)++;
    }
    oldsum += a;
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    unsigned long long sum = 0;
    int b, c;
    cin >> b >> c;
    if (m.count(b) == 0) {
      cout << oldsum << endl;
      continue;
    }
    if (m.count(c) == 0) {
      sum += oldsum;
      sum -= b * m.at(b);
      m[c] = 0;
      m.at(c) = m.at(b);
      m.erase(b);
    } else {
      sum += oldsum;
      sum -= b * m.at(b);
      sum -= c * m.at(c);
      m.at(c) += m.at(b);
      m.erase(b);
    }
    sum += c * m.at(c);
    cout << sum << endl;
    oldsum = sum;
  }
  return 0;
}
