#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target( \
    "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC target("avx512f,avx512dq,avx512cd,avx512bw,avx512vl")
using namespace std;
int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q;
  cin >> n;
  vector<int> a(100001);
  int total = 0, temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    total += temp;
    a[temp]++;
  }
  cin >> q;
  vector<pair<int, int>> b(q);
  int num1, num2, ntemp, diff;
  for (int i = 0; i < q; i++) {
    cin >> num1 >> num2;
    diff = num2 - num1;
    total += (a[num1] * diff);
    a[num2] += a[num1];
    a[num1] = 0;
    cout << total << endl;
  }
  return 0;
}
