#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
int main() {
  int n, q;
  cin >> n;
  vector<int> A(n);
  vector<int> num(100001, 0);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    num[A[i]]++;
  }
  cin >> q;
  vector<int> B(q);
  vector<int> C(q);
  for (int i = 0; i < q; i++) {
    cin >> B[i] >> C[i];
  }
  int sum = 0;
  for (int i = 0; i < n; i++) {
    sum += A[i];
  }
  for (int i = 0; i < q; i++) {
    sum += num[B[i]] * (C[i] - B[i]);
    cout << sum << endl;
    num[C[i]] += num[B[i]];
    num[B[i]] = 0;
  }
  return 0;
}
