#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long N;
  vector<long long> A(pow(10, 5) + 10);
  cin >> N;
  long long sum = 0;
  for (long long i = 0; i < N; i++) {
    long long a;
    cin >> a;
    A[a]++;
    sum += a;
  }
  long long Q;
  cin >> Q;
  vector<long long> ans(Q);
  for (long long i = 0; i < Q; i++) {
    long long b, c;
    cin >> b >> c;
    long long x = A[b];
    sum -= b * x;
    sum += c * x;
    A[c] += x;
    ans[i] = sum;
  }
  for (long long i = 0; i < Q; i++) cout << ans[i] << endl;
}
