#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  int A[n];
  long long suma = 0;
  map<int, int> counter;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    suma += A[i];
    counter[A[i]]++;
  }
  int q;
  cin >> q;
  for (int qq = 0; qq < q; qq++) {
    int b, c;
    cin >> b >> c;
    int counter_b = counter[b];
    counter[b] = 0;
    counter[c] += counter_b;
    suma -= b * counter_b;
    suma += c * counter_b;
    cout << suma << "\n";
  }
}
