#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, q;
  int sum = 0;
  cin >> n;
  map<int, int> a;
  for (int i = 0; i < n; ++i) {
    int tmp;
    cin >> tmp;
    sum += tmp;
    if (a.count(tmp) == 0) {
      a[tmp] = 1;
    } else {
      ++a[tmp];
    }
  }
  cin >> q;
  int b[q], c[q];
  for (int i = 0; i < q; ++i) {
    cin >> b[i];
    cin >> c[i];
  }
  int sum_a[q];
  for (int i = 0; i < q; ++i) {
    int tmp = 0;
    if (a.count(b[i])) {
      tmp = (c[i] - b[i]) * a[b[i]];
      if (a.count(c[i])) {
        a[c[i]] += a[b[i]];
      } else {
        a[c[i]] = a[b[i]];
      }
      a.erase(b[i]);
    }
    if (i == 0) {
      sum_a[i] = sum + tmp;
    } else {
      sum_a[i] = sum_a[i - 1] + tmp;
    }
  }
  for (int i = 0; i < q; ++i) {
    cout << sum_a[i] << "\n";
  }
}
