#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, arr[100005], b, c, q;
  while (cin >> n) {
    vector<long long> ans;
    long long sum;
    for (auto i = 0; i < n; i++) cin >> arr[i];
    cin >> q;
    for (auto i = 0; i < q; i++) {
      sum = 0;
      cin >> b >> c;
      for (auto j = 0; j < n; j++) {
        if (arr[j] == b) arr[j] = c;
        sum += arr[j];
      }
      ans.push_back(sum);
    }
    for (auto x : ans) cout << x << '\n';
  }
  return 0;
}
