#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int main() {
  int n;
  cin >> n;
  map<int, int> mp;
  long long int sum = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    mp[a]++;
    sum += a;
  }
  int Q;
  cin >> Q;
  vector<long long int> ans(Q);
  for (int i = 0; i < Q; ++i) {
    int b, c;
    cin >> b >> c;
    sum -= b * mp[b];
    sum += c * mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    ans[i] = sum;
  }
  for (int i = 0; i < Q; ++i) cout << ans[i] << endl;
  return 0;
}
