#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;
int main() {
  long long int n;
  cin >> n;
  map<long long int, long long int> a;
  for (int i = 0; i < n; ++i) {
    long long int t;
    cin >> t;
    if (a.count(t)) {
      ++a[t];
    } else {
      a[t] = 1;
    }
  }
  long long int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    long long int b, c;
    cin >> b >> c;
    if (a.count(b)) {
      if (a.count(c)) {
        a[c] += a[b];
        a.erase(b);
      } else {
        a[c] = a[b];
        a.erase(b);
      }
    }
    long long int sum = 0;
    for (auto t : a) {
      auto k = t.first;
      auto v = t.second;
      sum += k * v;
    }
    cout << sum << endl;
  }
}
