#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const char nl = '\n';
void solve() {
  int n;
  cin >> n;
  ll sum = 0;
  unordered_map<int, int> count;
  int a;
  while (n--) {
    cin >> a;
    sum += a;
    ++count[a];
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int valcount = count[b];
    sum -= b * valcount;
    count.erase(b);
    sum += c * valcount;
    count[c] += valcount;
    cout << sum << nl;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(nullptr);
  solve();
  return 0;
}
