#include <bits/stdc++.h>
using namespace std;
const int maxi = 2000000000;
const int maxq = 1000000000;
const long long mod = 1000000007LL;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, sum = 0;
  cin >> n;
  long long a[n];
  for (long long i = (0); i < (n); ++i) {
    cin >> a[i];
    sum += a[i];
  }
  long long x;
  cin >> x;
  while (x--) {
    long long c, d;
    cin >> c >> d;
    for (long long i = (0); i < (n); ++i) {
      if (a[i] == c) {
        a[i] = d;
        sum = sum + d - c;
      }
    }
    cout << sum << endl;
  }
  return 0;
}
