#include <bits/stdc++.h>
using namespace std;
template <class... A>
void prints() {
  cout << "\n";
}
template <class... A>
void prints_rest() {
  cout << "\n";
}
template <class T, class... A>
void prints_rest(const T &first, const A &...rest) {
  cout << " " << first;
  prints_rest(rest...);
}
template <class T, class... A>
void prints(const T &first, const A &...rest) {
  cout << first;
  prints_rest(rest...);
}
template <class T, class... A>
void printd(const T &first, const A &...rest) {
  cout << fixed << setprecision(15) << first;
  prints_rest(rest...);
}
namespace {
void printElems(const int *begin, const int *end) {
  for (const int *p = begin; p != end; ++p) {
    std::cout << *p << ' ';
  }
  std::cout << std::endl;
}
}  // namespace
const long long llinf = numeric_limits<long long>::max();
const long long _llinf = numeric_limits<long long>::lowest();
const int inf = numeric_limits<int>::max();
const int _inf = numeric_limits<int>::lowest();
const double dinf = numeric_limits<double>::infinity();
const long long MOD = 1000000007;
const long long BIG = 1LL << 60;
long long a[100005];
int main() {
  long long n;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  long long q;
  cin >> q;
  map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    decltype(m)::iterator it = m.find(a[i]);
    if (it != m.end()) {
      m[a[i]]++;
    } else {
      m.insert(make_pair(a[i], 1));
    }
  }
  vector<long long> anslist;
  for (int _ = 0; _ < q; _++) {
    long long b, c;
    cin >> b >> c;
    long long tmp = m[b];
    m.erase(b);
    decltype(m)::iterator it = m.find(c);
    if (it != m.end()) {
      m[c] += tmp;
    } else {
      m.insert(make_pair(c, tmp));
    }
    long long ans = 0;
    for (auto itr = m.begin(); itr != m.end(); ++itr) {
      ans += (itr->first) * (itr->second);
    }
    anslist.push_back(ans);
  }
  for (const auto &x : anslist) {
    prints(x);
  }
  return 0;
}
