#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;
  int n;
  cin >> n;
  map<int, int> m;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    if (m.count(a)) {
      ++m[a];
    } else {
      m[a] = 1;
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; ++i) {
    int b, c;
    cin >> b >> c;
    if (m.count(c) == 0) {
      m[c] = 0;
    }
    if (m.count(b) == 0) {
      m[b] = 0;
    }
    int cb = m[b];
    m[c] += cb;
    m[b] -= cb;
    long long sum = 0;
    for (auto it = m.begin(); it != m.end(); ++it) {
      sum += it->first * it->second;
    }
    cout << sum << endl;
  }
  return 0;
}
