#include <bits/stdc++.h>
int main() {
  long n;
  std::cin >> n;
  std::unordered_multiset<long> a;
  for (long i = 0; i < n; ++i) {
    long aa;
    std::cin >> aa;
    a.emplace(aa);
  }
  long q;
  std::cin >> q;
  long b, c;
  {
    std::cin >> b >> c;
    const long count = a.count(b);
    a.erase(b);
    for (long j = 0; j < count; ++j) {
      a.emplace(c);
    }
  }
  auto previous = std::accumulate(std::begin(a), std::end(a), 0l);
  std::cout << previous << std::endl;
  for (long i = 1; i < q; ++i) {
    std::cin >> b >> c;
    const long count = a.count(b);
    a.erase(b);
    for (long j = 0; j < count; ++j) {
      a.emplace(c);
    }
    previous -= (b * count);
    previous += (c * count);
    std::cout << previous << std::endl;
  }
}
