#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> vec(n);
  for (int i = 0; i < n; ++i) {
    cin >> vec[i];
  }
  int q;
  cin >> q;
  vector<vector<int>> che(q, vector<int>(2));
  for (int i = 0; i < q; ++i) {
    cin >> che[i][0] >> che[i][1];
  }
  map<int, int> num;
  for (int i = 0; i < n; ++i) {
    num[vec[i]]++;
  }
  int ans = 0;
  for (const auto& [key, value] : num) {
    ans += key * value;
  }
  for (int i = 0; i < q; ++i) {
    if (num.count(che[i][0])) {
      if (num.count(che[i][1])) {
        ans += (che[i][1] - che[i][0]) * num[che[i][0]];
        num[che[i][1]] += num[che[i][0]];
        num.erase(che[i][0]);
      } else {
        ans += (che[i][1] - che[i][0]) * num[che[i][0]];
        num[che[i][1]] = num[che[i][0]];
        num.erase(che[i][0]);
      }
    }
    cout << ans << endl;
  }
}
