#include <bits/stdc++.h>
using namespace std;
long long int occur(int arr[], int n, int b, int c) {
  long long int sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += arr[i];
    if (arr[i] == b) {
      arr[i] = c;
      sum = sum - b + c;
    }
  }
  return sum;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, t, i, q, b, c;
  cin >> n;
  int a[n + 1];
  long long int sum = 0, ans;
  for (i = 0; i < n; i++) cin >> a[i];
  cin >> q;
  for (i = 0; i < q; ++i) {
    t = 0, ans = 0;
    cin >> b >> c;
    ans = occur(a, n, b, c);
    cout << ans << endl;
  }
  return 0;
}
