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