#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long x, n, q, sum = 0, a, b;
  int arr[100005];
  cin >> n;
  for (int i = 0; i <= n; i++) {
    arr[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> x;
    sum += x;
    arr[x]++;
  }
  cin >> q;
  while (q--) {
    cin >> a >> b;
    sum -= (a * arr[a]);
    sum -= (b * arr[b]);
    int temp = arr[a];
    arr[a] = 0;
    arr[b] += temp;
    sum += (b * arr[b]);
    cout << sum << "\n";
  }
  return 0;
}
