#include <bits/stdc++.h>
using namespace std;
class DReplacing {
 public:
  static constexpr int kStressCount = 0;
  static void generateTest(ostream& test) {}
  void solve(istream& cin, ostream& cout) {
    int n;
    cin >> n;
    vector<int> cnt(1e5 + 1);
    for (int i = 0; i < n; i++) {
      int tmp;
      cin >> tmp;
      cnt[tmp]++;
    }
    int q;
    cin >> q;
    long long ans = 0;
    for (int i = 0; i < 1e5 + 1; i++) {
      ans += i * cnt[i];
    }
    for (int i = 0; i < q; i++) {
      int b, c;
      cin >> b >> c;
      cnt[c] += cnt[b];
      ans -= b * cnt[b];
      ans += c * cnt[b];
      cnt[b] = 0;
      cout << ans << "\n";
    }
  }
};
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  istream& in(cin);
  ostream& out(cout);
  out << fixed;
  out.precision(20);
  DReplacing solver;
  solver.solve(in, out);
}
