#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
using VI = vector<int>;
using VB = vector<bool>;
using VS = vector<string>;
using graph = vector<vector<int>>;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, q, ans = 0, b, c, n_count;
  cin >> n;
  VI a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    ans += a.at(i);
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    cin >> b >> c;
    n_count = count(a.begin(), a.end(), b);
    replace(a.begin(), a.end(), b, c);
    ans = ans + (c - b) * n_count;
    cout << ans << '\n';
  }
  return 0;
}
