#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
int n;
map<int, int> a;
void input() {
  a.clear();
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    a[t]++;
  }
}
void solve() {
  ll sum = 0;
  for (auto&& [key, val] : a) sum += key * val;
  int q;
  cin >> q;
  while (q--) {
    int b;
    int c;
    cin >> b >> c;
    sum -= b * a[b];
    sum += c * a[b];
    a[c] += a[b];
    a[b] = 0;
    cout << sum << '\n';
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(16);
  cout << fixed;
  int _times = 1;
  while (_times--) {
    input();
    solve();
  }
}
