#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (a % b == 0) {
    return b;
  } else {
    return (gcd(b, a % b));
  }
}
int main() {
  int n, q;
  cin >> n;
  vector<int> a(n);
  vector<int> count(100001, 0);
  for (int i = 0; i < (int)(n); i++) {
    cin >> a.at(i);
    count.at(a.at(i))++;
  }
  cin >> q;
  vector<int> b(q);
  vector<int> c(q);
  for (int i = 0; i < (int)(q); i++) cin >> b.at(i) >> c.at(i);
  long long sum = 0;
  for (int i = 0; i < (int)(100001); i++) {
    sum += i * count.at(i);
  }
  for (int i = 0; i < (int)(q); i++) {
    sum -= count.at(b.at(i)) * b.at(i);
    sum += count.at(b.at(i)) * c.at(i);
    count.at(c.at(i)) += count.at(b.at(i));
    count.at(b.at(i)) = 0;
    cout << sum << endl;
  }
}
