#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5;
const int M = 1000000007;
vector<int> adj[MAX + 1];
vector<int> rev_adj[MAX + 1];
stack<int> dif_topo;
vector<bool> visited(MAX + 1, 0);
vector<vector<int> > res;
void dfs1(int u) {
  for (auto v : adj[u]) {
    if (visited[v] == 0) {
      visited[v] = 1;
      dfs1(v);
    }
  }
  dif_topo.push(u);
}
void dfs2(int u) {
  for (auto v : rev_adj[u]) {
    if (visited[v] == 0) {
      visited[v] = 1;
      res.back().push_back(v);
      dfs2(v);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int money[n + 1];
  for (int i = 1; i <= n; i++) {
    cin >> money[i];
  }
  int m;
  cin >> m;
  while (m--) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    rev_adj[v].push_back(u);
  }
  for (int i = 1; i <= n; i++) {
    if (visited[i] == 0) {
      visited[i] = 1;
      dfs1(i);
    }
  }
  visited.assign(MAX + 1, 0);
  while (!dif_topo.empty()) {
    int x = dif_topo.top();
    dif_topo.pop();
    if (visited[x] == 1) continue;
    res.push_back({x});
    visited[x] = 1;
    dfs2(x);
  }
  long long sum = 0, method = 1;
  for (auto v : res) {
    int a = 2 * 1e9, b = 1;
    for (auto x : v) {
      if (money[x] < a)
        a = money[x], b = 1;
      else if (money[x] == a)
        b++;
    }
    sum += a, method = method * b % M;
  }
  cout << sum << " " << method;
}
