#include <bits/stdc++.h>
using namespace std;
long long const MAX = 2147483647, REALMAX = 9223372036854775806;
long long const N = 1e5 + 2, MOD = 1e9 + 7;
long long cost[N];
bool vis[N];
vector<long long> v[N], r_v[N], order;
long long ans, ways_this_scc, ways_all_scc = 1, cost_this_scc;
void DFS(long long curr) {
  vis[curr] = 1;
  for (long long c : v[curr])
    if (!vis[c]) DFS(c);
  order.push_back(curr);
}
void r_DFS(long long curr) {
  vis[curr] = 1;
  if (cost[curr] == cost_this_scc) ways_this_scc++;
  if (cost[curr] < cost_this_scc) {
    cost_this_scc = cost[curr];
    ways_this_scc = 1;
  }
  for (long long c : r_v[curr])
    if (!vis[c]) r_DFS(c);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n;
  cin >> n;
  for (long long i = (1); i < (n + 1); i++) cin >> cost[i];
  long long m;
  cin >> m;
  for (long long i = (0); i < (m); i++) {
    long long x, y;
    cin >> x >> y;
    v[x].push_back(y);
    r_v[y].push_back(x);
  }
  for (long long i = (1); i < (n + 1); i++)
    if (!vis[i]) DFS(i);
  memset(vis, 0, sizeof vis);
  for (long long i = (order.size() - 1); i >= 0; i--) {
    int curr = order[i];
    cost_this_scc = MAX;
    ways_this_scc = 0;
    if (!vis[curr]) {
      r_DFS(curr);
      ans += cost_this_scc;
      ways_all_scc = (ways_all_scc * ways_this_scc) % MOD;
    }
  }
  cout << ans << " " << ways_all_scc;
}
