#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int arr[n];
  int sum = 0;
  unordered_map<int, int> m;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    m[arr[i]]++;
    sum = sum + arr[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    if (m[a] != 0) {
      sum = sum - m[a] * a;
      sum = sum + m[a] * b;
      cout << sum << endl;
      m[b] = m[b] + m[a];
      m[a] = 0;
    } else
      cout << sum << endl;
  }
}
