#include <bits/stdc++.h>
using namespace std;
const int Maxn = 1e5 + 1, Maxm = 3 * 1e5 + 11, P = 1e9 + 7;
struct Node {
  int to, lac;
} edge[Maxm];
long long ans, c[Maxn], b[Maxn], num, col[Maxn], sta[Maxn], dep, n, m, x, cnt,
    y, a[Maxn], h[Maxn], dfn[Maxn], top, low[Maxn];
bool fsta[Maxn], flag[Maxn];
void insert(int x, int y) {
  cnt++;
  edge[cnt].to = y;
  edge[cnt].lac = h[x];
  h[x] = cnt;
}
void tarjan(int u) {
  dfn[u] = low[u] = ++dep;
  flag[u] = 1;
  top++;
  sta[top] = u;
  fsta[u] = 1;
  for (int i = h[u]; i; i = edge[i].lac) {
    int to = edge[i].to;
    if (flag[to]) {
      if (fsta[to]) low[u] = min(low[u], dfn[to]);
      continue;
    }
    tarjan(to);
    low[u] = min(low[u], low[to]);
  }
  if (low[u] == dfn[u]) {
    num++;
    while (fsta[u]) {
      col[sta[top]] = num;
      fsta[sta[top]] = 0;
      top--;
    }
  }
  return;
}
int main() {
  scanf("%lld", &n);
  for (int i = 1; i <= n; i++) scanf("%lld", &a[i]);
  scanf("%lld", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%lld%lld", &x, &y);
    insert(x, y);
  }
  for (int i = 1; i <= n; i++)
    if (!flag[i]) tarjan(i);
  for (int i = 1; i <= num; i++) b[i] = 1e16;
  for (int i = 1; i <= n; i++) {
    if (a[i] < b[col[i]]) {
      c[col[i]] = 1;
      b[col[i]] = a[i];
    } else if (a[i] == b[col[i]])
      c[col[i]]++;
  }
  for (int i = 1; i <= num; i++) ans += b[i];
  printf("%lld ", ans);
  ans = 1;
  for (int i = 1; i <= num; i++) ans = (ans * c[i]) % P;
  printf("%lld", ans);
  return 0;
}
