#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  cin >> n;
  int x;
  long long sum = 0;
  int arr[100001];
  for (int i = 0; i < 100001; i++) arr[i] = 0;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  for (int i = 0; i < n; i++) {
    arr[a[i]]++;
    sum += a[i];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    long long temp = b * arr[b];
    sum -= temp;
    arr[c] += arr[b];
    sum += arr[b] * c;
    arr[b] = 0;
    cout << sum << endl;
  }
}
int main() {
  { solve(); }
  return 0;
}
