#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {
  return a < b && (a = b, true);
}
template <typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {
  return a > b && (a = b, true);
}
void app() {
  int n;
  cin >> n;
  map<int, int> a;
  int s = 0;
  for (int i = 0; i < (int)(n); i++) {
    int ai;
    cin >> ai;
    a[ai]++;
    s += ai;
  }
  int q;
  cin >> q;
  for (int t = 0; t < (int)(q); t++) {
    int b, c;
    cin >> b >> c;
    s += (c - b) * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << s << endl;
  }
}
int main() {
  app();
  return 0;
}
