#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  map<int, int> m;
  int *arr = new int[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    m[arr[i]]++;
  }
  int q;
  cin >> q;
  for (int z = 0; z < q; z++) {
    int b, c;
    cin >> b >> c;
    int temp = m[b];
    sum = sum + (c - b) * temp;
    m[b] = 0;
    m[c] = m[c] + temp;
    cout << sum << endl;
  }
  return 0;
}
