#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T>
void print(vector<T>& v, bool spaced = true) {
  int n = v.size();
  string space = (spaced ? " " : "");
  for (int i = 0; i < n; ++i) {
    cout << v[i] << space;
  }
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  int q;
  cin >> q;
  while (q--) {
    int b, c;
    cin >> b >> c;
    for (int i = 0; i < n; ++i) a[i] = (a[i] == b ? c : a[i]);
    int ans = 0;
    for (int i = 0; i < n; ++i) ans += a[i];
    cout << ans << '\n';
  }
  return 0;
}
