#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, q, b, c, sum = 0, temp;
  cin >> n;
  int arr[n];
  int fre[100000] = {0};
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    fre[arr[i] - 1]++;
    sum += arr[i];
  }
  cin >> q;
  while (q--) {
    cin >> b >> c;
    temp = fre[b - 1];
    fre[b - 1] = 0;
    fre[c - 1] += temp;
    sum = sum + (c - b) * temp;
    cout << sum << endl;
  }
  return 0;
}
