#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MAX_N = 10000000;
bool compare_by_b(pair<string, int64_t> a, pair<string, int64_t> b) {
  if (a.second != b.second)
    return a.second < b.second;
  else
    return a.first < b.first;
}
bool my_compare(pair<int64_t, int64_t> a, pair<int64_t, int64_t> b) {
  if (a.first != b.first) return a.first < b.first;
  if (a.second != b.second)
    return a.second > b.second;
  else
    return true;
}
int64_t modpow(int64_t a, int64_t n, int64_t mod1) {
  int64_t res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod1;
    a = a * a % mod1;
    n >>= 1;
  }
  return res;
}
int64_t factorial(int64_t n) {
  int64_t x = 1;
  for (int64_t i = 1; i <= n; i++) x *= i;
  return x;
}
int64_t gcd(int64_t a, int64_t b) { return b ? gcd(b, a % b) : a; }
int64_t func(int64_t a, int64_t b, int64_t& ans_x, int64_t& ans_y) {
  if (b == 0) {
    ans_x = 1;
    ans_y = 0;
    return a;
  } else {
    int64_t ret = func(b, (a % b), ans_y, ans_x);
    ans_y -= (a / b) * ans_x;
    return ret;
  }
}
int64_t par[MAX_N], ranking[MAX_N];
void init(int64_t n) {
  for (int64_t i = 0; i < n; i++) {
    par[i] = i;
    ranking[i] = 0;
  }
}
int64_t find(int64_t x) {
  if (par[x] == x)
    return x;
  else
    return par[x] = find(par[x]);
}
void unite(int64_t x, int64_t y) {
  x = find(x);
  y = find(y);
  if (x == y) return;
  if (ranking[x] < ranking[y])
    par[x] = y;
  else {
    par[y] = x;
    if (ranking[x] == ranking[y]) ranking[x]++;
  }
}
bool same(int64_t x, int64_t y) { return find(x) == find(y); }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64_t n, sum = 0;
  cin >> n;
  map<int64_t, int64_t> a;
  for (int64_t i = 0; i < n; i++) {
    int64_t b;
    cin >> b;
    sum += b;
    a[b]++;
  }
  int64_t q;
  cin >> q;
  for (int64_t i = 0; i < q; i++) {
    int64_t f, b;
    cin >> f >> b;
    for (auto p : a) {
      bool check = false;
      if (p.first == f) {
        sum += (b - f) * p.second;
        a.erase(f);
        a[b] += p.second;
        check = true;
      }
      if (check) break;
    }
    cout << sum << endl;
  }
  return 0;
}
