#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  map<int, int> m;
  long long int total = 0;
  int num;
  for (int i = 0; i < n; ++i) {
    cin >> num;
    v[i] = num;
    total += num;
    m[num] += 1;
  }
  int q;
  cin >> q;
  while (q--) {
    long long int b, c;
    cin >> b >> c;
    if (m[b]) {
      long long int preB = m[b];
      long long int preC = m[c];
      if (preB) {
        m[b] = 0;
        m[c] += preB;
        cout << total + preB * (c - b) << "\n";
      }
    } else {
      cout << total << "\n";
    }
  }
  return 0;
}
