#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
class FenwickTree {
 private:
  vector<long long> ft;

 public:
  int LSOne(int x) { return (x & (-x)); }
  FenwickTree(int n) { ft.assign(n + 1, 0); }
  long long rsq(int b) {
    long long sum = 0;
    for (; b; b -= LSOne(b)) sum += ft[b];
    return sum;
  }
  long long rsq(int a, int b) { return rsq(b) - (a == 1 ? 0 : rsq(a - 1)); }
  void update(int k, int v) {
    for (; k < (int)ft.size(); k += LSOne(k)) ft[k] += v;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long f[N] = {};
  int n;
  cin >> n;
  long long a[n];
  for (auto &i : a) cin >> i, f[i]++;
  FenwickTree ft(N);
  for (auto &i : a) ft.update(i, i);
  int q;
  cin >> q;
  while (q--) {
    long long b, c;
    cin >> b >> c;
    if (f[b]) {
      ft.update(b, -f[b] * b);
      ft.update(c, f[b] * c);
      f[c] += f[b];
      f[b] = 0;
    }
    cout << ft.rsq(1, N) << "\n";
  }
  return 0;
}
