#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using numr = std::numeric_limits<T>;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
const int INF = 1e9;
const ll LLINF = 1e16;
const int MOD = 1000000007;
const int MOD2 = 998244353;
int main() {
  std::cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  int n, q;
  cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    if (std::find(A.begin(), A.end(), b) != A.end()) {
      std::replace(A.begin(), A.end(), b, c);
    }
    ll sum = std::accumulate(A.begin(), A.end(), 0);
    cout << sum << endl;
  }
}
