#include <bits/stdc++.h>
using namespace std;
long long cost[100005];
vector<long long> adj[100005];
vector<long long> radj[100005];
long long modd = 1000000007;
long long vis[100005];
long long rvis[100005];
stack<long long> s;
void dfs(long long i) {
  vis[i] = 1;
  for (long long u = 0; u < adj[i].size(); u++) {
    if (vis[adj[i][u]] == 0) {
      dfs(adj[i][u]);
    }
  }
  s.push(i);
}
void rdfs(long long i, long long &mini, long long &count) {
  rvis[i] = 1;
  if (cost[i] == mini) {
    count = (count + 1) % modd;
  }
  if (cost[i] < mini) {
    mini = cost[i];
    count = 1;
  }
  for (long long u = 0; u < radj[i].size(); u++) {
    if (rvis[radj[i][u]] == 0) {
      rdfs(radj[i][u], mini, count);
    }
  }
}
int main() {
  long long N;
  cin >> N;
  for (long long i = 1; i <= N; i++) {
    cin >> cost[i];
    vis[i] = 0;
    rvis[i] = 0;
  }
  long long M;
  cin >> M;
  long long u, v;
  for (long long i = 0; i < M; i++) {
    cin >> u >> v;
    adj[u].push_back(v);
    radj[v].push_back(u);
  }
  for (long long i = 1; i <= N; i++) {
    if (vis[i] == 0) {
      dfs(i);
    }
  }
  long long money = 0;
  long long ways = 1;
  while (!s.empty()) {
    long long start = s.top();
    s.pop();
    long long mini = 1000000007;
    long long count = 0;
    if (rvis[start] == 0) {
      rdfs(start, mini, count);
      money = money + mini;
      ways = (ways * count) % modd;
    }
  }
  cout << money << " " << ways << endl;
}
