#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;

#define EPS (1e-7)

int main() {
  ll N;
  cin >> N;
  vector<ll> A(N);
  for_each(begin(A), end(A), [](auto& x) { cin >> x; });
  ll Q;
  cin >> Q;
  vector<ll> B(Q);
  vector<ll> C(Q);
  for (ll i = 0; i < Q; i++) {
    cin >> B[i] >> C[i];
  }
  for (ll i = 0; i < Q; i++) {
    replace(begin(A), end(A), B[i], C[i]);
    ll sum = accumulate(cbegin(A), cend(A), 0LL);
    cout << sum << endl;
  }

  return 0;
}


