#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
string join(const T &v, const string delim = ",") {
  if (v.empty()) return "";
  ostringstream res;
  res << v[0];
  for (int i = 1; i < v.size(); i++) {
    res << delim << v[i];
  }
  return res.str();
}
int main() {
  int N;
  cin >> N;
  vector<int> a(100001);
  ll sum = 0;
  for (ll i = (ll)(0); i < (ll)(N); i++) {
    int n;
    cin >> n;
    a[n]++;
    sum += n;
  }
  int Q;
  cin >> Q;
  for (ll q = (ll)(0); q < (ll)(Q); q++) {
    int B, C;
    cin >> B >> C;
    sum -= (B * a[B]);
    sum += (C * a[B]);
    a[C] += a[B];
    a[B] = 0;
    cout << sum << endl;
  }
}
