#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;
const int MAX = 1e5;
int main() {
  int n;
  cin >> n;
  ll sum = 0;
  vi a(2 * MAX);
  map<int, vector<int>> cnt;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i + n]);
    cnt[a[i + n]].push_back(i);
  }
  auto build = [&]() {
    for (int i = n - 1; i >= 0; i--) {
      a[i] = a[i << 1] + a[i << 1 | 1];
    }
  };
  auto update = [&](int p, int val) {
    for (a[p += n] = val; p > 1; p >>= 1) {
      a[p >> 1] = a[p] + a[p ^ 1];
    }
  };
  auto query = [&](int l, int r) {
    int ret_val = 0;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) {
        ret_val += a[l++];
      }
      if (r & 1) {
        ret_val += a[--r];
      }
    }
    return ret_val;
  };
  build();
  int Q;
  cin >> Q;
  while (Q--) {
    ll b, c;
    cin >> b >> c;
    for (auto x : cnt[b]) {
      update(x, c);
    }
    for (auto x : cnt[b]) {
      cnt[c].push_back(x);
    }
    cnt.erase(b);
    cout << query(0, n + 1) << endl;
  }
  return 0;
}
