#include <bits/stdc++.h>
using namespace std;
int main() {
  const int MAX = 100000;
  int N;
  array<int, MAX> AList;
  int Q;
  array<int, MAX> BList;
  array<int, MAX> CList;
  cin >> N;
  for (int i = 0; i < N; i++) {
    int A;
    cin >> A;
    AList[i] = A;
  }
  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int B;
    int C;
    cin >> B >> C;
    BList[i] = B;
    CList[i] = C;
  }
  for (int i = 0; i < Q; i++) {
    long result = 0;
    replace(AList.begin(), AList.end(), BList[i], CList[i]);
    result = accumulate(AList.begin(), AList.end(), 0);
    cout << result << endl;
  }
  return 0;
}
