#include <bits/stdc++.h>
using namespace std;
void DBG() { cout << "]\n"; }
template <class H, class... T>
void DBG(H h, T... t) {
  cout << h;
  if (sizeof...(t)) {
    cout << ", ";
  }
  DBG(t...);
}
int n, m;
int cost[100010];
struct Edge {
  int v, nxt;
} e[300010];
int head[100010], cnt_e;
void add(int u, int v) {
  e[++cnt_e] = (Edge){v, head[u]};
  head[u] = cnt_e;
}
int dfn[100010], low[100010], tim;
int id[100010], tot, mn[100010], cnt[100010];
int sta[100010], tail;
bool vis[100010];
void tarjan(int x) {
  dfn[x] = low[x] = ++tim;
  sta[++tail] = x;
  vis[x] = 1;
  for (int i = head[x]; i; i = e[i].nxt) {
    int v = e[i].v;
    if (!dfn[v]) {
      tarjan(v);
      low[x] = min(low[x], low[v]);
    } else if (vis[v]) {
      low[x] = min(low[x], low[v]);
    }
  }
  if (dfn[x] == low[x]) {
    ++tot;
    int tmp = sta[tail];
    while (dfn[x] <= low[tmp]) {
      id[tmp] = tot;
      if (cost[tmp] < mn[tot]) {
        mn[tot] = cost[tmp];
        cnt[tot] = 1;
      } else if (cost[tmp] == mn[tot]) {
        cnt[tot]++;
      }
      vis[tmp] = 0;
      tail--;
      tmp = sta[tail];
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &cost[i]);
  scanf("%d", &m);
  int u, v;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &u, &v);
    add(u, v);
  }
  memset(mn, 0x3f3f3f3f, sizeof(mn));
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) tarjan(i);
  for (int i = 1; i <= n; i++) 0;
  long long money = 0, num = 1;
  for (int i = 1; i <= tot; i++) {
    money = money + mn[i];
    num = num * cnt[i] % ((int)1e9 + 7);
  }
  printf("%lld %lld\n", money, num);
}
