#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int A;
  int Q;
  int B, C;
  int sum;
  int num;
  int x[100000];
  cin >> N;
  for (int i = 1; i <= N; i++) {
    cin >> A;
    x[A]++;
    sum = A + sum;
  }
  cin >> Q;
  vector<int> calc(Q);
  for (int i = 0; i < Q; i++) {
    cin >> B >> C;
    num = C - B;
    calc[i] = num * x[B] + sum;
    sum = calc[i];
    x[C] = x[C] + x[B];
    x[B] = 0;
  }
  for (int i = 0; i < Q; i++) {
    cout << calc[i] << endl;
  }
  return 0;
}
