#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:66777216")
using namespace std;
int a, b, c, d, i, j, n, m, k;
vector<int> sm[200002];
int dp[200002], next3[200002], h[200002], cs[200002];
void dfs(int v, int pr = -1) {
  cs[v] = 1;
  int i = 0;
  while (i < (int)((sm[v]).size())) {
    int w = sm[v][i];
    if (w == pr) {
      swap(sm[v][i], sm[v].back());
      sm[v].pop_back();
      continue;
    }
    h[w] = h[v] + 1;
    dfs(w, v);
    cs[v] += cs[w];
    next3[v] = next3[w];
    ++i;
  }
  if (pr == -1 || (int)((sm[v]).size()) == 2) next3[v] = v;
}
int get_down(int v, int c) {
  if (!c) return v;
  return get_down(sm[v][0], c - 1);
}
int rec(int v, bool root = false);
int rec2(int v1, int v2) {
  if ((int)((sm[v1]).size()) == 0 && (int)((sm[v2]).size()) == 0) return 1;
  if (next3[v1] != -1 && next3[v2] != -1) return 0;
  if (cs[v1] > cs[v2]) swap(v1, v2);
  if (next3[v1] != -1) return 0;
  if (next3[v2] != -1) {
    int down2 = h[next3[v2]] - h[v2];
    int down1 = cs[v1] - 1;
    if (down1 >= down2) return 0;
  }
  if (cs[v1] == cs[v2] && next3[v1] == -1 && next3[v2] == -1) return 1;
  return rec(get_down(v2, cs[v1]));
}
int check(int v, int w, int left) {
  if (next3[left] != -1) return 0;
  int cnt = h[w] - h[v];
  if ((cnt + cs[left]) % 2) return 0;
  if (cs[left] > cnt) return 0;
  return 1;
}
int check2(int v, int w) {
  int cnt = h[w] - h[v];
  if (cnt % 2) return 0;
  return 1;
}
int check3(int v, int w, int left) {
  if (next3[left] != -1) return 0;
  int cnt = h[w] - h[v];
  if (cs[left] >= cnt) return 0;
  if ((cnt - cs[left] - 1) % 2 == 1) return 0;
  return 1;
}
int rec(int v, bool root) {
  if (root) {
    vector<int> ind;
    for (int _n((3) - 1), i(0); i <= _n; i++) ind.push_back(i);
    int ans = 0;
    do {
      int left = sm[v][ind[0]];
      int middle = sm[v][ind[1]];
      int right = sm[v][ind[2]];
      if ((int)((sm[middle]).size()) == 0) {
        ans = (ans + (long long)rec(left) * rec(right)) % 1000000007;
      }
      if ((int)((sm[middle]).size()) == 1) {
        ans = (ans + (long long)rec(left) * rec2(right, sm[middle][0])) %
              1000000007;
        ans = (ans + (long long)rec2(left, sm[middle][0]) * rec(right)) %
              1000000007;
      }
      if ((int)((sm[middle]).size()) == 2) {
        ans = (ans + (long long)rec2(left, sm[middle][0]) *
                         rec2(right, sm[middle][1])) %
              1000000007;
        ans = (ans + (long long)rec2(left, sm[middle][1]) *
                         rec2(right, sm[middle][0])) %
              1000000007;
      }
    } while (next_permutation((ind).begin(), (ind).end()));
    return ans;
  }
  if (dp[v] != -1) return dp[v];
  if (cs[v] % 2 == 1) return dp[v] = 0;
  if (cs[v] == 2) return dp[v] = 1;
  int ans = 0;
  if (next3[v] == -1) return cs[v] / 2;
  if ((int)((sm[v]).size()) == 1) {
    int w = next3[v];
    for (int _n((2) - 1), i(0); i <= _n; i++) {
      int down = sm[w][i];
      int right = sm[w][i ^ 1];
      if ((int)((sm[down]).size()) == 0) {
        if (check2(v, w)) ans = (ans + rec(right)) % 1000000007;
      } else if ((int)((sm[down]).size()) == 1) {
        if (check2(v, w)) ans = (ans + rec2(right, sm[down][0])) % 1000000007;
        if (check(v, w, sm[down][0])) ans = (ans + rec(right)) % 1000000007;
      } else if ((int)((sm[down]).size()) == 2) {
        if (check(v, w, sm[down][0]))
          ans = (ans + rec2(right, sm[down][1])) % 1000000007;
        if (check(v, w, sm[down][1]))
          ans = (ans + rec2(right, sm[down][0])) % 1000000007;
      }
      int left = down;
      if (check3(v, w, left)) ans = (ans + rec(right)) % 1000000007;
    }
    return dp[v] = ans;
  }
  for (int _n((2) - 1), i(0); i <= _n; i++) {
    int w = sm[v][i];
    int o = sm[v][i ^ 1];
    if ((int)((sm[w]).size()) == 2) continue;
    if ((int)((sm[w]).size()) == 0)
      ans = (ans + rec(o)) % 1000000007;
    else
      ans = (ans + rec2(o, sm[w][0])) % 1000000007;
  }
  return dp[v] = ans;
}
int solve() {
  int root = -1;
  for (int _n((m)-1), i(0); i <= _n; i++) {
    if ((int)((sm[i]).size()) > 3) return 0;
    if ((int)((sm[i]).size()) == 3) root = i;
  }
  if (root == -1) {
    if (n == 1)
      return ((long long)n * n - n + 2) % 1000000007;
    else
      return ((long long)n * n - n + 2) * 2 % 1000000007;
  }
  h[root] = 0;
  memset(next3, -1, m * sizeof(int));
  dfs(root);
  memset(dp, -1, m * sizeof(int));
  return 2LL * rec(root, 1) % 1000000007;
}
int main() {
  scanf("%d", &n);
  m = 2 * n;
  for (int _n((m - 1) - 1), i(0); i <= _n; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    sm[a].push_back(b);
    sm[b].push_back(a);
  }
  printf("%d\n", solve());
}
