#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int hash[100001] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    hash[arr[i]]++;
  }
  int q;
  cin >> q;
  int a, b;
  int sum = 0;
  int prev;
  while (q--) {
    sum = 0;
    cin >> a >> b;
    if (hash[a] != 0) {
      hash[b] = hash[a];
      hash[a] = 0;
      for (int i = 0; i <= 100000; i++) {
        sum = sum + (i * hash[i]);
      }
      prev = sum;
    } else {
      cout << prev << endl;
    }
  }
}
