#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  template <class c>
  debug& operator<<(const c&) {
    return *this;
  }
};
void solve() {
  int n;
  cin >> n;
  int mxn = 1e5 + 5;
  vector<int> cnt(mxn);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
    sum += x;
  }
  int q;
  cin >> q;
  vector<long long> ans;
  while (q--) {
    int b, c;
    cin >> b >> c;
    sum = sum - cnt[b] * b + c * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    ans.push_back(sum);
  }
  for (long long a : ans) {
    cout << a << "\n";
  }
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
