#include <bits/stdc++.h>
const int dx4[4] = {-1, 0, 1, 0}, dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {-1, -1, 0, 1, 1, 1, 0, -1},
          dy8[8] = {0, -1, -1, -1, 0, 1, 1, 1};
const int mod = 1e9 + 7;
const int mod2 = 998244353;
using namespace std;
template <class T>
void readV(vector<T> &arr) {
  for (int i = 0; i < arr.size(); i++) cin >> arr[i];
}
template <class T>
void printV(vector<T> &arr) {
  for (int i = 0; i < arr.size(); i++) cout << arr[i] << " ";
}
template <class T>
void readArray(T arr[], int n) {
  for (int i = 0; i < n; i++) cin >> arr[i];
}
template <class T>
void printArray(T arr[], int n) {
  for (int i = 0; i < n; i++) cout << arr[i] << " ";
}
template <class T>
void rArray(T arr[], int n) {
  for (int i = 0, j = n - 1; i < j; i++, j--) {
    int t = arr[i];
    arr[i] = arr[j];
    arr[j] = t;
  }
}
void makeWeightedEdges(vector<vector<pair<int, int> > > &edges) {
  for (int i = 0; i < edges.size(); i++) {
    int s, d, wt;
    cin >> s >> d >> wt;
    edges[s].push_back(make_pair(d, wt));
    edges[d].push_back(make_pair(s, wt));
  }
}
void makeUnweightedEdges(vector<vector<int> > &edges) {
  for (int i = 0; i < edges.size(); i++) {
    int s, d;
    cin >> s >> d;
    edges[s].push_back(d);
    edges[d].push_back(s);
  }
}
void dfs1(vector<vector<int> > &edges, vector<bool> &vis, int index,
          stack<int> &s) {
  vis[index] = true;
  for (auto i : edges[index]) {
    if (vis[i] == false) {
      dfs1(edges, vis, i, s);
    }
  }
  s.push(index);
}
void dfs2(vector<vector<int> > &redges, vector<bool> &vis, vector<int> &v,
          int index) {
  for (auto i : redges[index]) {
    if (vis[i] == false) {
      v.push_back(i);
      vis[i] = true;
      dfs2(redges, vis, v, i);
    }
  }
}
void connectedComponents(vector<vector<int> > &redges, vector<bool> &vis,
                         stack<int> &s, vector<vector<int> > &cc) {
  while (!s.empty()) {
    if (vis[s.top()] == true) {
      s.pop();
    } else {
      vector<int> v;
      vis[s.top()] = true;
      v.push_back(s.top());
      dfs2(redges, vis, v, s.top());
      s.pop();
      cc.push_back(v);
    }
  }
}
void solve() {
  int n;
  cin >> n;
  int cost[n];
  readArray(cost, n);
  vector<vector<int> > edges(n);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int s, d;
    cin >> s >> d;
    edges[s - 1].push_back(d - 1);
  }
  vector<bool> vis(n, false);
  stack<int> s;
  for (int i = 0; i < n; i++) {
    if (vis[i] == false) dfs1(edges, vis, i, s);
  }
  vector<vector<int> > redges(n);
  for (int i = 0; i < n; i++) {
    if (edges[i].size() != 0) {
      for (auto j : edges[i]) {
        redges[j].push_back(i);
      }
    }
  }
  for (int i = 0; i < n; i++) {
    vis[i] = false;
  }
  vector<vector<int> > cc;
  connectedComponents(redges, vis, s, cc);
  long long total = 0;
  int c[cc.size()];
  int index = 0;
  for (auto i : cc) {
    int min = INT_MAX;
    for (auto j : i) {
      if (cost[j] < min) {
        c[index] = 1;
        min = cost[j];
      } else if (cost[j] == min) {
        c[index]++;
      }
    }
    index++;
    total += min;
  }
  long long ways = 1;
  for (auto i : c) {
    ways = ways * 1LL * i;
  }
  ways = (ways % mod);
  cout << total << " " << ways << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
