#include <bits/stdc++.h>
using namespace std;
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int IsPrime(long long int n) {
  if ((n % 2 == 0 && n != 2) || n == 1) return 0;
  for (long long int i = 3; i * i <= n; i += 2) {
    if (n % i == 0) return 0;
  }
  return 1;
}
int sieve(long long int N) {
  bool isPrime[N + 1];
  for (long long int i = 0; i <= N; ++i) {
    isPrime[i] = true;
  }
  isPrime[0] = false;
  isPrime[1] = false;
  for (long long int i = 2; i * i <= N; ++i) {
    if (isPrime[i] == true) {
      for (int j = i * i; j <= N; j += i) isPrime[j] = false;
    }
  }
}
int maxsubarraysum(int a[], int size) {
  int max_so_far = INT_MIN, max_ending_here = 0;
  for (int i = 0; i < size; i++) {
    max_ending_here = max_ending_here + a[i];
    if (max_so_far < max_ending_here) max_so_far = max_ending_here;
    if (max_ending_here < 0) max_ending_here = 0;
  }
  return max_so_far;
}
int maxSubArraySum(int a[], int size) {
  int max_so_far = 0, max_ending_here = 0;
  for (int i = 0; i < size; i++) {
    max_ending_here = max_ending_here + a[i];
    if (max_ending_here < 0)
      max_ending_here = 0;
    else if (max_so_far < max_ending_here)
      max_so_far = max_ending_here;
  }
  return max_so_far;
}
int max_sum_subarray(int arr[], int n) {
  int meh = 0, msf = INT_MIN;
  for (int i = 0; i < n; i++) {
    meh = meh + arr[i];
    if (msf < meh) msf = meh;
    if (meh < 0) meh = 0;
  }
  return msf;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long int n;
  cin >> n;
  long long int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long int q;
  cin >> q;
  while (q--) {
    long long int b, c;
    cin >> b >> c;
    for (int i = 0; i < n; i++) {
      if (a[i] == b) {
        a[i] = c;
      }
    }
    long long int ans = 0;
    for (int i = 0; i < n; i++) {
      ans += a[i];
    }
    cout << ans << endl;
  }
}
