#include <bits/stdc++.h>
using namespace std;
long long prime[1000000];
void sieve() {
  prime[0] = 0;
  prime[1] = 0;
  for (long long i = 2; i < 1000000; i++) prime[i] = 1;
  for (long long i = 2; i * i < 1000000; i++)
    if (prime[i] == 1)
      for (long long j = i * i; j < 1000000; j += i) prime[j] = 0;
}
bool isPrime(long long n) {
  if (n <= 1) return false;
  for (long long i = 2; i <= floor(sqrt(n)); i++)
    if (n % i == 0) return false;
  return true;
}
long long factorial(long long n) {
  long long f = 1;
  for (long long i = 1; i <= n; i++) f = (f * i) % 1000000007;
  return f;
}
long long gcd(long long a, long long b) { return !b ? a : gcd(b, a % b); }
long long lcm(long long a, long long b) { return (a / gcd(a, b)) * b; }
long long fastExponentiation(long long n, long long x, long long modulo) {
  long long res = 1;
  while (x > 0) {
    if (x & 1) res = (res * n) % modulo;
    x = x >> 1;
    n = (n * n) % modulo;
  }
  return res;
}
long long power(long long n, long long p) {
  if (p == 0) return 1;
  long long res = power((n * n) % 1000000007, p / 2);
  if (p % 2 == 1) res = (n * res) % 1000000007;
  return res;
}
bool isPowerOfTwo(long long n) { return n && (!(n & (n - 1))); }
bool isSet(long long n, long long i) { return n & (1 << i); }
bool valid_coordinate(long long x, long long y, long long n, long long m) {
  if (x < 0 || y < 0)
    return false;
  else if (x >= n || y >= m)
    return false;
  else
    return true;
}
long long sod(long long n) {
  long long sum = 0;
  while (n) {
    sum += (n % 10);
    n /= 10;
  }
  return sum;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (long long i = 0; i < n; i++) cin >> v[i];
  long long q;
  cin >> q;
  vector<long long> a(q), b(q);
  for (long long i = 0; i < q; i++) cin >> a[i] >> b[i];
  for (long long i = 0; i < q; i++) {
    long long count = 0;
    for (long long j = 0; j < n; j++) {
      if (a[i] == v[j]) {
        v[j] = b[i];
      }
    }
    for (long long j = 0; j < n; j++) {
      count += v[j];
    }
    cout << count << "\n";
  }
}
int32_t main() {
  solve();
  return 0;
}
