#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> nums;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    nums.push_back(a);
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    long long total = 0;
    for (int j = 0; j < n; j++) {
      if (nums[j] == b) {
        nums[j] = c;
      }
    }
    for (int a = 0; a < n; a++) {
      total += nums[a];
    }
    cout << total << endl;
  }
  return 0;
}
