#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> arr(n);
  int num[100001];
  for (int i = 0; i <= 100000; i++) {
    num[i] = 0;
  }
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    sum += arr[i];
    num[arr[i]]++;
  }
  int q, b, c;
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    sum -= num[b] * b;
    sum += num[b] * c;
    cout << sum << "\n";
    num[c] += num[b];
    num[b] = 0;
  }
  return 0;
}
