#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ld = long double;
using VI = vector<ll>;
using VD = vector<ld>;
using VVI = vector<VI>;
using VC = vector<char>;
using VB = vector<bool>;
using VVC = vector<VC>;
using VS = vector<string>;
using PLL = pair<ll, ll>;
using PLD = pair<ld, ld>;
using VPLL = vector<PLL>;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int MOD = int(1e9) + 7;
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;
}
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first,
                              BidirectionalIterator middle,
                              BidirectionalIterator last) {
  reverse(middle, last);
  return next_permutation(first, last);
}
ll gcd(ll x, ll y) { return (x % y) ? gcd(y, x % y) : y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll GCD(VI v) {
  ll a = v[0];
  for (ll i = 1; i < ((ll)(v).size()); i++) {
    a = gcd(a, v[i]);
  }
  return a;
}
ll LCM(VI v) {
  ll a = v[0];
  for (ll i = 1; i < ((ll)(v).size()); i++) {
    a = lcm(a, v[i]);
  }
  return a;
}
VI Bit2Vector(const ll bit, ll n) {
  VI s;
  for (ll i = 0; i < (ll)(n); i++)
    if (bit & (1 << i)) s.push_back(i);
  return s;
}
void Main2() {
  ll n, m, l;
  ll res = 0;
  string s, t, u;
  string sres = "No or NO";
  cin >> n;
  VI a(n), b(n);
  VB c(n, false);
  for (ll i = 0; i < (ll)(n); i++) cin >> a[i];
  VVI ab(n);
  ll q;
  cin >> q;
  VPLL bc(q);
  for (ll i = 0; i < (ll)(q); i++) {
    ll b, c;
    cin >> b >> c;
    bc[q - i - 1].first = b;
    bc[q - i - 1].second = c;
  }
  for (ll i = 0; i < (ll)(n); i++) {
    if (c[i] = true) continue;
    for (auto v : bc) {
      if (a[i] == v.first) {
        a[i] = v.second;
        c[i] = true;
      }
    }
  }
  for (ll i = 0; i < (ll)(n); i++) {
    std::cout << a[i] << "\n";
  }
  return;
}
void Main() {
  ll n, m, l;
  ll res = 0;
  string s, t, u;
  string sres = "No or NO";
  cin >> n;
  VI a(n), b(n);
  VB c(n, false);
  for (ll i = 0; i < (ll)(n); i++) cin >> a[i];
  VVI ab(n);
  ll q;
  cin >> q;
  VPLL bc(q);
  for (ll i = 0; i < (ll)(q); i++) {
    ll b, c;
    cin >> b >> c;
    bc[i].first = b;
    bc[i].second = c;
  }
  for (ll i = 0; i < (ll)(q); i++) {
    for (ll j = 0; j < (ll)(n); j++) {
      if (bc[j].first == a[j]) a[j] = bc[j].second;
    }
    res = accumulate((a).begin(), (a).end(), 0);
    std::cout << res << "\n";
  }
  return;
}
int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
}
