#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  while (a) {
    if (a < b) {
      std::swap(a, b);
    }
    a %= b;
  }
  return b;
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
map<long long, long long> prime_factorization(long long n) {
  map<long long, long long> prime_factors;
  for (long long i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      prime_factors[i]++;
      n /= i;
    }
  }
  if (n != 1) prime_factors[n] = 1;
  return prime_factors;
}
vector<long long> get_divisors(const long long n) {
  vector<long long> divs;
  for (long long i = 1; i < (long long)sqrt((long double)n) + 1; i++) {
    if (n % i == 0) {
      divs.push_back(i);
      if (i != n / i) {
        divs.push_back(n / i);
      }
    }
  }
  return divs;
}
int main() {
  long long N;
  long long S = 0;
  cin >> N;
  vector<long long> A(N);
  for (int i = 0; i < (N); i++) cin >> A.at(i);
  long long Q;
  cin >> Q;
  vector<pair<long long, long long> > B(Q);
  for (int i = 0; i < (Q); i++) {
    S = 0;
    cin >> B.at(i).first >> B.at(i).second;
    replace(A.begin(), A.end(), B.at(i).first, B.at(i).second);
    for (int i = 0; i < (N); i++) {
      S += A.at(i);
    }
    cout << S << endl;
  }
  return 0;
}
