#include <bits/stdc++.h>
using namespace std;
template <class T>
inline istream& operator>>(istream& c, vector<T>& A) {
  for (int i = 0; i < (A.size()); ++i) c >> A[i];
  return c;
}
const long long linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  long long tmp = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    mp[a]++;
    tmp += a;
  }
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    int res = mp[b];
    mp[b] = 0;
    tmp -= b * res;
    tmp += c * res;
    mp[c] += res;
    printf("%lld\n", tmp);
  }
  return 0;
}
