#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5;
const int mod = 1e9 + 7;
const int inf = 0x7f7f7f7f;
int n;
int c[maxn];
int m;
vector<int> E1[maxn];
vector<int> E2[maxn];
int sz;
int a[maxn];
bool vis[maxn];
long long cost, ways;
int minc, cnt;
void dfs1(int u) {
  int i;
  int v;
  vis[u] = true;
  for (i = 0; i < E1[u].size(); ++i) {
    v = E1[u][i];
    if (!vis[v]) dfs1(v);
  }
  a[sz++] = u;
}
void dfs2(int u) {
  int i;
  int v;
  if (minc > c[u]) {
    minc = c[u];
    cnt = 1;
  } else if (minc == c[u])
    ++cnt;
  vis[u] = true;
  for (i = 0; i < E2[u].size(); ++i) {
    v = E2[u][i];
    if (!vis[v]) {
      vis[v] = true;
      dfs2(v);
    }
  }
}
int main(void) {
  int i;
  int u, v;
  scanf("%d", &n);
  for (i = 0; i < n; ++i) scanf("%d", c + i);
  scanf("%d", &m);
  for (i = 0; i < m; ++i) {
    scanf("%d %d", &u, &v);
    --u;
    --v;
    E1[u].push_back(v);
    E2[v].push_back(u);
  }
  for (i = 0; i < n; ++i) {
    if (!vis[i]) dfs1(i);
  }
  cost = 0;
  ways = 1;
  memset(vis, false, sizeof(vis[0]) * n);
  for (i = n - 1; i >= 0; --i) {
    if (!vis[a[i]]) {
      minc = inf;
      cnt = 1;
      dfs2(a[i]);
      cost += minc;
      (ways *= cnt) %= mod;
    }
  }
  printf("%lld %lld\n", cost, ways);
  return 0;
}
