#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int maxn = 100000;
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
void countFreq(int arr[], long long int n,
               vector<pair<long long int, long long int> > &v) {
  vector<bool> visited(n, false);
  for (int i = 0; i < n; i++) {
    if (visited[i] == true) continue;
    int count = 1;
    for (int j = i + 1; j < n; j++) {
      if (arr[i] == arr[j]) {
        visited[j] = true;
        count++;
      }
    }
    v.push_back(make_pair(arr[i], count));
  }
}
int main() {
  long long int k, n, i, sum = 0, q, b, c, sum1;
  vector<pair<long long int, long long int> > v;
  cin >> n;
  int ar[n];
  for (i = 0; i < n; i++) {
    cin >> ar[i];
    sum += ar[i];
  }
  countFreq(ar, n, v);
  cin >> q;
  while (q--) {
    cin >> b >> c;
    k = 0;
    for (i = 0; i < n; i++) {
      if (v[i].first == b) {
        sum = sum + (c - b) * v[i].second;
        k = 1;
        v[i].first = c;
      }
    }
    if (k == 1) {
      cout << sum << endl;
    }
  }
  return 0;
}
