#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(NULL);
  int n = 0;
  cin >> n;
  vector<int> nums;
  for (size_t i = 0; i < n; i++) {
    int temp;
    cin >> temp;
    nums.push_back(temp);
  }
  int n2;
  cin >> n2;
  for (size_t i = 0; i < n2; i++) {
    int a, b;
    cin >> a >> b;
    int sum = 0;
    for (int i = 0; i < nums.size(); i++) {
      if (nums[i] == a) nums[i] = b;
      sum += nums[i];
    }
    cout << sum << '\n';
    ;
  }
}
