#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using vll = vector<long long>;
using vvll = vector<vector<long long>>;
using vbool = vector<bool>;
using vvbool = vector<vector<bool>>;
using qint = queue<int>;
using sint = stack<int>;
using pii = pair<int, int>;
int main() {
  vector<ll> numbers(1e5 + 5, 0);
  int n;
  cin >> n;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    numbers[tmp]++;
    ans += tmp;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    numbers[c] += numbers[b];
    ans += (c - b) * numbers[b];
    cout << ans << endl;
  }
  return 0;
}
