#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
bool isperfect(long long n) {
  long long y = sqrt(n);
  if (n % y == 0 && y * y == n) return true;
  return false;
}
bool comp(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first) return a.second > b.second;
  return a.first < b.first;
}
long long powi(long long a, long long b) {
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = (ans * a);
    b = b >> 1;
    a = (a * a);
  }
  return ans;
}
bool isprime(long long n) {
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) return false;
  }
  return true;
}
bool prime[10000000];
void seive() {
  prime[1] = true;
  for (int i = 2; i * i < 10000000; i++) {
    if (prime[i]) continue;
    for (int j = i * i; j < 10000000; j += i) {
      prime[j] = true;
    }
  }
}
vector<long long int> v[200005];
vector<long long int> a(200005), p(200005);
bool vis[200005] = {false};
long long maxi = INT_MIN;
void dfs(int s, long long atil, long long ptil) {
  vis[s] = true;
  for (auto x : v[s]) {
    if (!vis[x]) {
      long long sm = (atil + a[x - 1]) / (ptil + p[x - 1]);
      if (sm > maxi) {
        maxi = sm;
        dfs(x, atil + a[x - 1], ptil + p[x - 1]);
      } else if (sm == maxi) {
        dfs(x, atil + a[x - 1], ptil + p[x - 1]);
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  vector<long long int> v(n);
  unordered_map<long long, long long> m;
  long long sum = 0;
  for (int i = 0; i < n; i++) cin >> v[i], m[v[i]]++, sum += v[i];
  long long q;
  cin >> q;
  while (q--) {
    long long p, r;
    cin >> p >> r;
    long long x = m[p];
    long long tt = sum - ((r - p) * x);
    m[p] = 0;
    m[r] += x;
    cout << tt << endl;
  }
}
