#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
const int N = 300005;
long long n, e, idx[N], low[N], T, q[300005], ans = 0, ans2 = 1, scc[100005],
                                              mini[300005], cn, second[3000005];
vector<vector<long long> > g;
vector<long long> S;
bool vis[N];
long long compID[N], cmp;
void DFS(int u) {
  idx[u] = low[u] = ++T;
  S.push_back(u);
  vis[u] = true;
  for (int i = 0; i < g[u].size(); ++i) {
    long long v = g[u][i];
    if (idx[v] == 0) DFS(v);
    if (vis[v]) low[u] = min(low[u], low[v]);
  }
  if (idx[u] == low[u]) {
    long long ee = 1e10;
    cn++;
    while (true) {
      long long v = S.back();
      ee = min(ee, q[v]);
      scc[v] = cn;
      S.pop_back();
      vis[v] = false;
      compID[v] = cmp;
      if (v == u) break;
    }
    mini[cn] = ee;
    ans += ee;
    ++cmp;
  }
}
int main() {
  cin >> n;
  g.resize(n);
  for (int i = 0; i < n; i++) cin >> q[i];
  cin >> e;
  for (int i = 0; i < e; ++i) {
    int from, to;
    cin >> from >> to;
    --from;
    --to;
    g[from].push_back(to);
  }
  for (int i = 0; i < n; ++i) {
    if (idx[i] == 0) {
      DFS(i);
    }
  }
  for (int i = 0; i < n; i++) {
    int in1 = scc[i];
    int uu = mini[in1];
    if (q[i] == uu) second[in1]++;
  }
  for (int i = 1; i <= cn; i++) {
    ans2 *= second[i];
    ans2 %= mod;
  }
  cout << ans << " " << ans2;
  return 0;
}
