#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
T ceil(T a, T b) {
  return a / b + !!(a % b);
}
int n, q;
vector<int> a, b, c;
map<int, ll> mp;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  a.resize(n);
  ll sum = 0;
  for (int i = 0; i < (n); ++i) {
    cin >> a[i];
    mp[a[i]]++;
    sum += a[i];
  }
  cin >> q;
  b.resize(q);
  c.resize(q);
  for (int i = 0; i < (q); ++i) {
    cin >> b[i] >> c[i];
    int cur = mp[b[i]];
    mp[b[i]] = 0;
    mp[c[i]] += cur;
    sum -= b[i] * cur;
    sum += c[i] * cur;
    cout << sum << endl;
  }
  return 0;
}
