#include <bits/stdc++.h>
using namespace std;
vector<int> solve(vector<int> &arr, vector<vector<int>> &op) {
  vector<int> output;
  int arrsum = 0;
  for (int i = 0; i < op.size(); i++) {
    for (int j = 0; j < arr.size(); j++) {
      if (arr[j] == op[i][0]) {
        arr[j] = op[i][1];
      }
    }
    for (int j = 0; j < arr.size(); j++) {
      arrsum += arr[j];
    }
    output.push_back(arrsum);
    arrsum = 0;
  }
  return output;
}
int main() {
  int numberOfElements = 0;
  int numberOfOperations = 0;
  cin >> numberOfElements;
  vector<int> arr(numberOfElements);
  for (int i = 0; i < numberOfElements; i++) {
    cin >> arr[i];
  }
  cin >> numberOfOperations;
  vector<vector<int>> op(numberOfOperations, vector<int>(2, 0));
  for (int i = 0; i < numberOfOperations; i++) {
    cin >> op[i][0];
    cin >> op[i][1];
  }
  vector<int> output(numberOfOperations);
  output = solve(arr, op);
  for (int i = 0; i < numberOfOperations; i++) {
    cout << output[i] << endl;
  }
  return 0;
}
