#include <bits/stdc++.h>
using namespace std;
int min(int x, int y) {
  if (x < y) return x;
  return y;
}
int max(int x, int y) {
  if (x > y) return x;
  return y;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  long long int sum = 0;
  cin >> n;
  vector<int> v(n);
  int a[10000] = {0};
  for (int i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    sum += temp;
    v.push_back(temp);
    a[temp - 1]++;
  }
  int q;
  cin >> q;
  while (q--) {
    int a1, a2, temp;
    cin >> a1 >> a2;
    sum = sum - a[a1 - 1] * a1;
    sum = sum + a[a1 - 1] * a2;
    temp = a[a1 - 1];
    a[a2 - 1] += temp;
    a[a1 - 1] = 0;
    cout << sum << endl;
  }
  return 0;
}
