#include <bits/stdc++.h>
using namespace std;
const int N = 100010, mod = 1000000007, INF = 1000000000;
int n, m, a, b, cost[N], mini, Counter;
long long pr1, pr2 = 1;
vector<int> adj[N], adj2[N], order;
bool vis[N];
void DFS1(int node) {
  if (vis[node]) return;
  vis[node] = 1;
  for (int i = 0; i < adj[node].size(); i++) DFS1(adj[node][i]);
  order.push_back(node);
}
void DFS2(int node) {
  if (vis[node]) return;
  vis[node] = 1;
  if (cost[node] < mini) mini = cost[node], Counter = 0;
  if (cost[node] == mini) Counter++;
  for (int i = 0; i < adj2[node].size(); i++) DFS2(adj2[node][i]);
}
void SCC() {
  for (int i = 0; i < n; i++)
    if (!vis[i]) DFS1(i);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < adj[i].size(); j++) adj2[adj[i][j]].push_back(i);
  memset(vis, 0, sizeof vis);
  for (int i = n - 1; i >= 0; i--) {
    if (!vis[order[i]]) {
      mini = INF, Counter = 0, DFS2(order[i]);
      pr1 += mini, pr2 = pr2 * Counter % mod, pr2 %= mod;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &cost[i]);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    adj[a - 1].push_back(b - 1);
  }
  SCC();
  printf("%I64d %I64d", pr1, pr2);
  return 0;
}
