#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, minus = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') minus = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x * minus;
}
const long long N = 1e5 + 5, MOD = 1e9 + 7;
long long n, m, a[N], ne[N * 3], go[N * 3], head[N];
long long low[N], dfn[N], c[N], s[N], p[N], l[N], tot, cnt, ans, ans1 = 1;
inline void Add(long long x, long long y) {
  ne[++tot] = head[x];
  head[x] = tot;
  go[tot] = y;
}
stack<long long> q;
inline void Tarjan(long long x) {
  dfn[x] = low[x] = ++cnt;
  q.push(x);
  for (register long long i = head[x]; i; i = ne[i]) {
    long long y = go[i];
    if (!dfn[y])
      Tarjan(y), low[x] = min(low[x], low[y]);
    else if (!c[y])
      low[x] = min(low[x], dfn[y]);
  }
  if (dfn[x] == low[x]) {
    c[x] = ++c[0];
    s[c[0]] = a[x];
    p[c[0]] = 1;
    while (q.top() != x) {
      c[q.top()] = c[0];
      if (s[c[0]] == a[q.top()])
        p[c[0]]++;
      else if (s[c[0]] > a[q.top()])
        s[c[0]] = a[q.top()], p[c[0]] = 1;
      q.pop();
    }
    q.pop();
  }
}
signed main() {
  n = read();
  for (register long long i = 1; i <= n; i++) a[i] = read();
  m = read();
  for (register long long i = 1; i <= m; i++) {
    long long x = read(), y = read();
    Add(x, y);
  }
  for (register long long i = 1; i <= n; i++)
    if (!dfn[i]) Tarjan(i);
  for (register long long i = 1; i <= c[0]; i++) {
    ans += s[i];
    ans1 *= p[i] % MOD;
  }
  printf("%lld %lld", ans, ans1 % MOD);
  return 0;
}
