#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  int k;
  cin >> n;
  int arr[n];
  int sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
  }
  cin >> k;
  int fre[100001] = {0};
  for (int i = 0; i < n; i++) fre[arr[i]]++;
  for (int i = 0; i < k; i++) {
    int a, b;
    cin >> a >> b;
    int oc = fre[a];
    sum = sum + (b - a) * oc;
    fre[b] += fre[a];
    fre[a] = 0;
    cout << sum << endl;
  }
}
int main() {
  long long int t;
  t = 1;
  while (t--) solve();
  return 0;
}
