#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
bool compare(pair<int, int>& p1, pair<int, int>& p2) {
  return p1.second < p2.second;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  long long sum = 0;
  map<int, int> m;
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    sum += temp;
    m[temp]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    if (m.find(b) != m.end()) {
      sum = sum - m[b] * b + m[b] * c;
      m[c] += m[b];
      cout << sum << "\n";
    } else
      cout << sum << "\n";
  }
}
