#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<int> v(n);
  map<int, int> count;
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    count[v[i]]++;
    sum += v[i];
  }
  int k;
  cin >> k;
  while (k--) {
    int a, c;
    cin >> a >> c;
    sum -= count[a] * a;
    sum += count[a] * c;
    count[c] += count[a];
    count[a] = 0;
    cout << sum << "\n";
  }
}
