#include <bits/stdc++.h>
using namespace std;
const int N = 300006;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> h;
  long long sum = 0;
  for (int& x : a) {
    cin >> x;
    h[x] += 1;
    sum += x;
  }
  int q;
  cin >> q;
  while (q--) {
    int x, y;
    cin >> x >> y;
    sum -= x * h[x];
    sum += y * h[x];
    h[y] += h[x];
    h[x] = 0;
    cout << sum << '\n';
  }
  return 0;
}
