#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const int N = 1e5 + 5;
const int INF = 1e9 + 5;
vector<ll> frq(N, 0);
void done() {
  ll n;
  cin >> n;
  ll a[n];
  ll total = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    frq[a[i]]++;
    total += a[i];
  }
  ll q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    ll b, c;
    cin >> b >> c;
    total = 0;
    for (int j = 0; j < n; j++) {
      if (a[j] == b) {
        a[j] = c;
        frq[a[j]]--;
        frq[c]++;
      }
      total += a[j];
    }
    cout << total << '\n';
  }
}
void solve() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  int sum = 0;
  for (int i = 0; i < k; i++) {
    sum += a[i];
  }
  cout << sum << '\n';
}
void another() {}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  done();
}
