#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  vector<long long> v(100000, 0);
  long long n;
  cin >> n;
  long long sum = 0;
  while (n--) {
    int a;
    cin >> a;
    v[a - 1]++;
    sum += a;
  }
  int m;
  cin >> m;
  while (m--) {
    int d, cc;
    cin >> d >> cc;
    int jj = v[d - 1];
    v[d - 1] = 0;
    v[cc - 1] += jj;
    sum -= jj * d;
    sum += jj * cc;
    cout << sum << "\n";
  }
  return 0;
}
