#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, sum = 0, temp;
  cin >> n;
  vector<int> c(100005, 0);
  vector<int> v(n + 1);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    c[v[i]]++;
    sum += v[i];
  }
  int q, a, b, s = sum;
  cin >> q;
  while (q--) {
    cin >> a >> b;
    s = s - c[a] * a;
    s = s + c[b] * b;
    cout << s << endl;
    c[b] += c[a];
    c[a] = 0;
  }
}
int main() {
  solve();
  return 0;
}
