#include <bits/stdc++.h>
using namespace std;
bool isPrime(long long n) {
  if (n <= 1) return false;
  if (n <= 3) return true;
  if (n % 2 == 0 || n % 3 == 0) return false;
  for (long long i = 5; i * i <= n; i = i + 6)
    if (n % i == 0 || n % (i + 2) == 0) return false;
  return true;
}
int minthis(int a, int b) {
  if (a < b) {
    return a;
  }
  return b;
}
int maxthis(int a, int b) {
  if (a > b) {
    return a;
  }
  return b;
}
int gcd(int a, int b) {
  if (a < 0) a = -a;
  if (b < 0) b = -b;
  while (b != 0) {
    a %= b;
    if (a == 0) return b;
    b %= a;
  }
  return a;
}
int findLargestDivisor(int n) {
  int max = 1;
  for (int i = 2; i < n; i++) {
    if (n % (i) == 0) {
      max = i;
    }
  }
  return max;
}
long long power(long long x, long long y) {
  long long temp;
  if (y == 0) return 1;
  temp = power(x, y / 2);
  if (y % 2 == 0)
    return temp * temp;
  else {
    if (y > 0)
      return x * temp * temp;
    else
      return (temp * temp) / x;
  }
}
void solve() {
  int n;
  cin >> n;
  int sum = 0;
  unordered_map<int, int> make_pair;
  unordered_map<int, int>::iterator it;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    make_pair[x]++;
    sum += x;
  }
  int x;
  cin >> x;
  while (x--) {
    int a, b;
    cin >> a >> b;
    it = make_pair.find(a);
    if (it == make_pair.end()) {
      cout << sum << "\n";
      continue;
    }
    sum -= it->first * it->second;
    sum += it->second * b;
    make_pair[b] += it->second;
    make_pair.erase(it);
    cout << sum << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
