#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, Q, s = 0;
  cin >> N;
  map<long long, long long> m;
  for (int i = 0; i < (N); ++i) {
    long long t;
    cin >> t;
    if (m.count(t))
      ++m.at(t);
    else
      m[t] = 1;
    s += t;
  }
  cin >> Q;
  for (int i = 0; i < (Q); ++i) {
    long long B, C;
    cin >> B >> C;
    s = s - B * m.at(B) + C * m.at(B);
    if (m.count(C))
      m.at(C) += m.at(B);
    else
      m[C] = m.at(B);
    m.erase(B);
    cout << s << endl;
  }
}
