#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int arr[n];
  int fre[100005] = {0};
  long long int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum = sum + arr[i];
    fre[arr[i]]++;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    int c = fre[a];
    fre[a] = 0;
    fre[b] = fre[b] + c;
    sum = sum - (c * a) + (c * b);
    cout << sum << endl;
  }
}
