#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int sum = 0, max = 0, min = 0;
vector<int> a;
void solve() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int item;
    cin >> item;
    a.push_back(item);
    sum += item;
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int b, c;
    cin >> b >> c;
    int val = count(a.begin(), a.end(), b);
    sum -= (val * b);
    sum += (val * c);
    replace(a.begin(), a.end(), b, c);
    cout << sum << endl;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
