#include <bits/stdc++.h>
using namespace std;
using lli = long long int;
using vvint = vector<vector<int>>;
const int mod = 1e9 + 7;
const int N = 2e5 + 1;
void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  multiset<int> s;
  lli summ = 0;
  for (int i = 0; i < n; ++i) cin >> a[i], summ = summ + a[i], s.insert(a[i]);
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    auto itr = s.find(b);
    while (itr != s.end()) {
      summ = summ - b + c;
      s.erase(itr);
      s.insert(c);
      itr = s.find(b);
    }
    cout << summ << "\n";
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout << fixed << setprecision(10);
  int t = 1;
  while (t--) solve();
  return 0;
}
