#include <bits/stdc++.h>
using namespace std;
struct edge {
  int v, w;
};
vector<edge> g[200001];
int dfn[200001], low[200001], bel[200001], dfc, bcc;
int bcs[200001], *bct = bcs;
void bcc_clr(int n) { fill(dfn + 1, dfn + n + 1, 0); }
int dfs_bcc(int u, int f) {
  *bct++ = u;
  dfn[u] = low[u] = ++dfc;
  for (edge e : g[u]) {
    int v = e.v;
    if (v == f) continue;
    if (!dfn[v])
      low[u] = min(low[u], dfs_bcc(v, u));
    else
      low[u] = min(low[u], low[v]);
  }
  if (dfn[u] == low[u])
    for (++bcc; *bct != u; --bct) bel[bct[-1]] = bcc;
  return low[u];
}
struct edge0 {
  int u, v, w;
} es[200001];
long long a[200001], b[200001], a1[200001], b1[200001];
void fwt(long long* a, int n, long long P) {
  for (int k = 1; k < n; k <<= 1)
    for (int m = k << 1, i = 0; i < n; i += m)
      for (int j = 0; j != k; j++) {
        long long x = a[i + j], y = a[i + j + k];
        a[i + j] = (((x + y) + P) % P);
        a[i + j + k] = (((x - y) + P) % P);
      }
}
void ifwt(long long* a, int n, long long P) {
  for (int k = 1; k < n; k <<= 1)
    for (int m = k << 1, i = 0; i < n; i += m)
      for (int j = 0; j != k; j++) {
        long long x = a[i + j], y = a[i + j + k];
        a[i + j] = ((((((x + y) + P) % P) * ((P + 1) / 2)) + P) % P);
        a[i + j + k] = ((((((x - y) + P) % P) * ((P + 1) / 2)) + P) % P);
      }
}
int main(void) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int u, v, w;
    scanf("%d%d%d", &u, &v, &w);
    es[i] = {u, v, w};
    g[u].push_back({v, w});
    g[v].push_back({u, w});
  }
  dfs_bcc(1, 0);
  int c = m - n + 1;
  map<int, vector<int>> sv;
  int sum = 0, cnt = 0;
  for (int i = 1; i <= m; ++i) {
    if (bel[es[i].u] != bel[es[i].v])
      sum ^= es[i].w;
    else
      sv[bel[es[i].u]].push_back(es[i].w);
  }
  int w = 1 << 17, t = 0;
  for (const pair<int, vector<int>>& p : sv) {
    int xs = 0;
    for (int x : p.second) xs ^= x;
    if (t == 0) {
      for (int x : p.second) a[sum ^ xs ^ x]++;
      for (int x : p.second) a1[sum ^ xs ^ x]++;
      fwt(a, w, 1000000007);
      fwt(a1, w, 1145140019);
    } else {
      fill(b, b + w, 0);
      fill(b1, b1 + w, 0);
      for (int x : p.second) b[xs ^ x]++;
      for (int x : p.second) b1[xs ^ x]++;
      fwt(b, w, 1000000007);
      fwt(b1, w, 1145140019);
      for (int i = 0; i != w; ++i) a[i] = a[i] * b[i] % 1000000007;
      for (int i = 0; i != w; ++i) a1[i] = a1[i] * b1[i] % 1145140019;
    }
    ++t;
  }
  if (!c) {
    printf("%d %d", sum, 1);
  } else {
    ifwt(a, w, 1000000007);
    ifwt(a1, w, 1145140019);
    int v = 0;
    while (!a[v] && !a1[v]) ++v;
    printf("%d %lld", v, a[v]);
  }
  return 0;
}
