#include <bits/stdc++.h>
using namespace std;
int arr[1000000];
int main() {
  int n, m, sum = 0;
  cin >> n;
  for (int i = 0, x; i < n; i++) {
    cin >> x;
    sum += x;
    arr[x]++;
  }
  cin >> m;
  int arr2[2];
  for (int i = 0; i < m; i++) {
    cin >> arr2[0] >> arr2[1];
    sum = sum - (arr[arr2[0]] * arr2[0]) + (arr[arr2[0]] * arr2[1]);
    cout << sum;
    if (i != m - 1) {
      cout << endl;
    }
    arr[arr2[1]] += arr[arr2[0]];
    arr[arr2[0]] = 0;
  }
  return 0;
}
