#include <bits/stdc++.h>
using namespace std;
int const INF = 0x3fffffff;
int const MOD = 1e9 + 7;
int const MAX = 1e5 + 5;
int n, m, a[MAX];
int cur, dfn[MAX], low[MAX];
bool ins[MAX];
vector<int> vt[MAX];
stack<int> stk;
long long ans, tot;
void Tarjan(int u) {
  dfn[u] = low[u] = ++cur;
  stk.push(u);
  ins[u] = true;
  for (int i = 0; i < (int)vt[u].size(); i++) {
    int v = vt[u][i];
    if (!dfn[v]) Tarjan(v);
    if (ins[v]) low[u] = min(low[u], low[v]);
  }
  if (dfn[u] == low[u]) {
    int mi = INF, cnt = 0, v;
    do {
      v = stk.top();
      stk.pop();
      ins[v] = false;
      if (a[v] < mi) {
        mi = a[v];
        cnt = 0;
      }
      if (a[v] == mi) cnt++;
    } while (u != v);
    ans += mi;
    tot = ((tot % MOD) * (cnt % MOD)) % MOD;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  while (m--) {
    int x, y;
    scanf("%d %d", &x, &y);
    vt[x].push_back(y);
  }
  tot = 1;
  for (int i = 1; i <= n; i++)
    if (!dfn[i]) Tarjan(i);
  printf("%I64d %I64d\n", ans, tot);
}
