#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000 + 1;
const int maxm = 300000 + 1;
const int max_cost = 1000000000 + 1;
int n, m;
vector<int> cost = {0};
vector<vector<int> > graph;
vector<vector<int> > Tgraph;
int used[maxn];
int used2[maxn];
vector<int> order;
vector<vector<int> > component;
void dfs(int u) {
  used[u] = 1;
  auto adj = Tgraph[u];
  for (int i = 1; i < adj.size(); i++) {
    if (used[adj[i]] == 0) {
      dfs(adj[i]);
    }
  }
  order.push_back(u);
}
void dfs2(int u, int cnt) {
  used2[u] = 1;
  component[cnt].push_back(u);
  if (component[cnt][0] > cost[u]) {
    component[cnt][0] = cost[u];
    component[cnt][1] = 1;
  } else if (component[cnt][0] == cost[u])
    component[cnt][1]++;
  auto adj = graph[u];
  for (int i = 1; i < adj.size(); i++) {
    if (used2[adj[i]] == 0) {
      dfs2(adj[i], cnt);
    }
  }
}
int main() {
  cin >> n;
  for (int i = 0; i <= n; i++) {
    graph.push_back(cost);
    Tgraph.push_back(cost);
  }
  int a;
  for (int i = 0; i < n; i++) {
    cin >> a;
    cost.push_back(a);
  }
  cin >> m;
  int b;
  for (int i = 0; i < m; i++) {
    cin >> a >> b;
    graph[a].push_back(b);
    Tgraph[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    if (0 == used[i]) {
      dfs(i);
    }
  }
  int cnt = 0;
  long long sum = 0;
  long long ways = 1;
  vector<int> c = {max_cost, 0};
  component.push_back(c);
  for (int i = 1; i <= n; i++) {
    if (0 == used2[order[n - i]]) {
      cnt++;
      component.push_back(c);
      dfs2(order[n - i], cnt);
      sum += component[cnt][0];
      ways *= component[cnt][1];
    }
  }
  cout << sum << ' ' << ways % 1000000007;
  return 0;
}
