#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  a = abs(a), b = abs(b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
void solve() {
  long long n;
  cin >> n;
  unordered_map<long long, long long> h;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    h[t]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    long long sum = 0;
    cin >> b >> c;
    if (h[b]) {
      int t = h[b];
      h.erase(b);
      h[c] += t;
    }
    for (auto& [key, val] : h) {
      sum += val * key;
    }
    cout << sum << endl;
  }
}
int main() {
  solve();
  return 0;
}
