#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int dp[200000];
  int a[N];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
    dp[a[i]]++;
    sum += a[i];
  }
  int Q;
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int num = 0;
    int B, C;
    cin >> B >> C;
    num = dp[B];
    dp[B] = 0;
    dp[C] += num;
    sum += num * (C - B);
    cout << sum << endl;
  }
}
