#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> A;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    A.push_back(x);
  }
  unordered_map<int, int> mp;
  int sum = 0;
  for (int i = 0; i < A.size(); i++) {
    mp[A[i]]++;
    sum += A[i];
  }
  int m;
  cin >> m;
  while (m--) {
    int x, y;
    cin >> x >> y;
    int occur = mp[x];
    sum = sum - occur * x;
    mp[x] = 0;
    mp[y] += occur;
    sum += occur * y;
    cout << sum << endl;
  }
  return 0;
}
