#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3", "unroll-loops")
long long mod = 1e9 + 7;
template <typename T>
T nCr(T n, T r) {
  if (r > n - r) r = n - r;
  int ans = 1, i;
  for (i = 1; i <= r; i++) {
    ans *= n - r + i;
    ans /= i;
  }
  return ans;
}
template <typename T, typename T2>
T2 power(T x, T y) {
  if (y == 0) return 1;
  T2 res = power(x, y / 2);
  if (y % 2) return res * res * x;
  return res * res;
}
template <typename T>
long long countSetBits(T n) {
  return __builtin_popcount(n);
}
template <typename T>
bool isPrime(T 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;
}
bool ispalindrome(string s) {
  long long len = s.length();
  for (long long i = 0; i < len; i++) {
    if (s[i] != s[len - i - 1]) return false;
  }
  return true;
}
int32_t main() {
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  ;
  cout << fixed << setprecision(20);
  ;
  long long n;
  cin >> n;
  map<long long, long long> m;
  long long a[n];
  long long res = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    m[a[i]]++;
    res += a[i];
  }
  long long q;
  cin >> q;
  while (q--) {
    long long x, y;
    cin >> x >> y;
    res -= m[x] * x;
    res += m[x] * y;
    m[y] += m[x];
    m[x] = 0;
    cout << res % mod << "\n";
  }
  return 0;
}
