#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> m;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (m.count(x))
      m[x]++;
    else
      m[x] = 1;
  }
  cin >> x;
  for (int i = 0; i < x; i++) {
    int b, c;
    cin >> b >> c;
    if (m.count(c))
      m[c] += m[b];
    else
      m[c] = m[b];
    m.erase(b);
    long long ans = 0;
    for (auto p : m) {
      auto key = p.first;
      auto value = p.second;
      ans += key * value;
    }
    cout << ans << endl;
  }
}
