#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + (s - '0');
    s = getchar();
  }
  return x * f;
}
const int jzm = 1000000007;
int n, m, i, j, s, o, k;
vector<int> g[100005];
int v[100005], dfn[100005], low[100005], cnt;
int c[100005], bel[100005];
struct itn {
  int nm, cn;
  itn() {
    nm = 0x7f7f7f7f;
    cn = 0;
  }
  itn(int N, int C) { nm = N, cn = C; }
} mi[100005];
itn bing(itn a, itn b) {
  if (a.nm != b.nm)
    return a.nm < b.nm ? a : b;
  else
    return itn(a.nm, a.cn + b.cn);
}
stack<int> st;
void dfs(int x) {
  v[x] = 1;
  dfn[x] = low[x] = ++cnt;
  st.push(x);
  for (int i = 0; i < g[x].size(); i++) {
    if (v[g[x][i]] > 1) continue;
    if (!v[g[x][i]]) {
      dfs(g[x][i]);
      low[x] = min(low[x], low[g[x][i]]);
    } else {
      low[x] = min(low[x], dfn[g[x][i]]);
    }
  }
  if (dfn[x] == low[x]) {
    while (!st.empty() && v[x] < 2) {
      int t = st.top();
      st.pop();
      bel[t] = x;
      v[t] = 2;
      mi[x] = bing(mi[x], itn(c[t], 1));
    }
  }
  return;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    c[i] = read();
  }
  m = read();
  for (int i = 1; i <= m; i++) {
    s = read();
    o = read();
    g[s].push_back(o);
  }
  for (int i = 1; i <= n; i++) {
    if (!v[i]) {
      dfs(i);
    }
  }
  long long ans = 0;
  int ans2 = 1;
  for (int i = 1; i <= n; i++) {
    if (bel[i] == i) {
      ans += (long long)mi[i].nm;
      ans2 = ans2 * 1ll * mi[i].cn % jzm;
    }
  }
  printf("%lld %d\n", ans, ans2);
  return 0;
}
