#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T;
  cin >> T;
  long long int arr[100002];
  long long int sum = 0;
  for (int i = 0; i < T; i++) {
    int temp;
    cin >> temp;
    sum += temp;
    arr[temp]++;
  }
  int Q;
  cin >> Q;
  while (Q--) {
    int B, C;
    cin >> B >> C;
    long long int temp = arr[B];
    sum -= B * temp;
    sum += C * temp;
    arr[B] -= temp;
    arr[C] += temp;
    cout << sum << endl;
  }
}
