#include <bits/stdc++.h>
using namespace std;
inline int Get() {
  int res = 0, q = 1;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') q = -1, ch = getchar();
  while (ch >= '0' && ch <= '9') res = res * 10 + ch - '0', ch = getchar();
  return res * q;
}
const double eps = 1e-12, pi = M_PI;
const int oo = (int)2e9, mod = (int)1e9 + 7;
const long long INF = (long long)1e17;
const int N = (int)2e5, LG = 19;
typedef int arr[N + 10];
typedef int arre[2 * N + 10];
int n, m, tot, j, k, rt, ans, st[2], sv[2], sc[4], tsc[3], ord[4], tord[3];
arr g, dep, deg, sz, f, h, l, son, ft, to[LG + 1];
arre pt, nt;
bool v[N + 10];
struct queue {
  arr v;
  int f, r;
} q;
void Link(int x, int y) {
  pt[++tot] = y, nt[tot] = g[x], g[x] = tot;
  pt[++tot] = x, nt[tot] = g[y], g[y] = tot;
}
int Find(int x, int y) {
  for (int c = LG; c >= 0; --c)
    if ((1 << c) <= y) y -= (1 << c), x = to[c][x];
  return x;
}
void Go(int x) {
  bool fx = h[st[0]], fy = h[st[1]];
  int dx = 1 + (fx ? dep[h[st[0]]] - dep[st[0]] : l[st[0]] - 1),
      dy = fy ? dep[h[st[1]]] - dep[st[1]] : l[st[1]] - 1;
  if (fx && fy)
    return;
  else if (fx) {
    if (dy >= dx) return;
    int dt = Find(st[0], dy);
    (f[x] += f[dt]) %= mod;
  } else if (fy) {
    if (dx >= dy) return;
    int dt = Find(st[1], dx + 1);
    (f[x] += f[dt]) %= mod;
  } else {
    if (dx == dy)
      (f[x] += 1) %= mod;
    else {
      int dt = dx > dy ? Find(st[0], dy) : Find(st[1], dx + 1);
      (f[x] += f[dt]) %= mod;
    }
  }
}
int Total(int x, int y) {
  if ((sz[x] + sz[y]) & 1) return 0;
  if (!y) return f[x];
  bool fx = h[x], fy = h[y];
  int dx = fx ? dep[h[x]] - dep[x] : l[x] - 1,
      dy = fy ? dep[h[y]] - dep[y] : l[y] - 1;
  if (fx && fy)
    return 0;
  else if (fx) {
    if (dy >= dx) return 0;
    int dt = Find(x, dy + 1);
    return f[dt];
  } else if (fy) {
    if (dx >= dy) return 0;
    int dt = Find(y, dx + 1);
    return f[dt];
  } else {
    if (dx == dy)
      return 1;
    else {
      int dt = dx > dy ? Find(x, dy + 1) : Find(y, dx + 1);
      return f[dt];
    }
  }
}
int Push(int x, int y, int d) {
  int cv = 0;
  sv[0] = sv[1] = 0;
  for (int i = g[x]; i; i = nt[i])
    if (pt[i] != ft[x]) sv[cv++] = pt[i];
  if (!cv) return 0;
  if (cv == 1) return l[sv[0]] == d ? f[y] : 0;
  int res = 0;
  if (l[sv[0]] == d) (res += Total(y, sv[1])) %= mod;
  if (l[sv[1]] == d) (res += Total(y, sv[0])) %= mod;
  return res;
}
void Dp(int x) {
  st[0] = st[1] = 0;
  if (deg[x] == 2) {
    int y = h[x];
    if (dep[y] - dep[x] > 1) (f[x] += f[son[son[x]]]) %= mod;
    if (!y)
      (f[x] += 1) %= mod;
    else {
      int dt = dep[y] - dep[x], cnt = 0;
      if (dt * 2 >= sz[x]) return;
      for (int i = g[y]; i; i = nt[i])
        if (pt[i] != ft[y]) st[cnt++] = pt[i];
      if (dt > 1) {
        if (l[st[0]] == dt - 1) (f[x] += f[st[1]]) %= mod;
        if (l[st[1]] == dt - 1) (f[x] += f[st[0]]) %= mod;
      }
      if (dt * 2 + 2 >= sz[x]) return;
      (f[x] += Push(st[0], st[1], dt)) %= mod;
      (f[x] += Push(st[1], st[0], dt)) %= mod;
    }
  } else {
    int cnt = 0;
    for (int i = g[x]; i; i = nt[i])
      if (pt[i] != ft[x]) st[cnt++] = pt[i];
    Go(x);
    swap(st[0], st[1]);
    Go(x);
  }
}
void Bfs() {
  q.v[1] = rt, q.f = q.r = 1, v[rt] = 1;
  for (; q.f <= q.r;) {
    int x = q.v[q.f++];
    for (int i = g[x]; i; i = nt[i])
      if (!v[pt[i]])
        q.v[++q.r] = pt[i], v[pt[i]] = 1, dep[pt[i]] = dep[x] + 1,
        ft[pt[i]] = x;
  }
  dep[0] = 2 * n + 10;
  for (int i = (q.r), end = (1); i >= end; --i) {
    int x = q.v[i];
    sz[x] = 1;
    l[x] = deg[x] == 1;
    for (int i = g[x]; i; i = nt[i])
      if (pt[i] != ft[x]) {
        sz[x] += sz[pt[i]], h[x] = h[pt[i]], son[x] = pt[i], to[0][x] = pt[i];
        if (l[pt[i]]) l[x] = l[pt[i]] + 1;
      }
    if (deg[x] > 2) h[x] = x, l[x] = 0;
    for (int j = (1), end = (LG); j <= end; ++j)
      to[j][x] = to[j - 1][to[j - 1][x]];
    if (x != rt && !(sz[x] & 1)) Dp(x);
  }
}
void Calc() {
  Bfs();
  int cntx = 0;
  for (int i = g[rt]; i; i = nt[i]) sc[++cntx] = pt[i], ord[cntx] = cntx;
  do {
    int cnty = 0;
    for (int i = g[sc[ord[2]]]; i; i = nt[i])
      if (pt[i] != rt) tsc[++cnty] = pt[i];
    cnty = 2, tord[1] = 1, tord[2] = 2;
    if (!tsc[1] && !tsc[2]) {
      int cx = Total(sc[ord[1]], 0), cy = Total(sc[ord[3]], 0);
      (ans += (long long)cx * (long long)cy % mod) %= mod;
      continue;
    }
    do {
      int cx = Total(sc[ord[1]], tsc[tord[1]]),
          cy = Total(sc[ord[3]], tsc[tord[2]]);
      (ans += (long long)cx * (long long)cy % mod) %= mod;
    } while (next_permutation(tord + 1, tord + cnty + 1));
    tsc[1] = tsc[2] = 0;
  } while (next_permutation(ord + 1, ord + cntx + 1));
}
int main() {
  scanf(
      "%d"
      "\n",
      &n);
  for (int i = (1), end = ((n << 1) - 1); i <= end; ++i) {
    scanf(
        "%d"
        "%d"
        "\n",
        &j, &k),
        Link(j, k);
    ++deg[j], ++deg[k];
    if (deg[j] > 3 || deg[k] > 3)
      return printf("0\n"), 0;
    else if (deg[j] == 3)
      rt = j;
    else if (deg[k] == 3)
      rt = k;
  }
  if (!rt) {
    if (n == 1)
      ans = 2;
    else
      ans =
          (2LL * (long long)n * (long long)n - 2LL * (long long)n + 4LL) % mod;
    return printf(
               "%d"
               "\n",
               ans),
           0;
  }
  Calc();
  printf(
      "%d"
      "\n",
      (ans << 1) % mod);
  return 0;
}
