#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  long long arr[n];
  int cnt[100001];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cnt[arr[i]]++;
    sum += arr[i];
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    long long x, y;
    cin >> x >> y;
    int diff = y - x;
    int c = cnt[x];
    sum = sum + diff * c;
    cnt[y] += cnt[x];
    cnt[x] = 0;
    cout << sum << endl;
  }
  return 0;
}
