#include <bits/stdc++.h>
using namespace std;
int n;
typedef struct {
  int id, b, c;
} ele;
int cmp(ele x, ele y) { return (x.b == x.c) < (y.b == y.c); }
vector<ele> e[200514];
ele bb[200514];
int cnt[200514];
int st[200514], top;
void dfs(int w) {
  for (int i = 0; i < ((int)e[w].size()); i++) {
    int l = e[w][i].b;
    int r = e[w][i].c;
    int id = e[w][i].id;
    if ((l == r && cnt[l] <= 7 + (l == w)) ||
        (l != r && cnt[l] <= 8 + (l == w) && cnt[r] <= 8 + (r == w))) {
      cnt[w]--;
      cnt[l]++;
      cnt[r]++;
      for (int j = i; j + 1 < ((int)e[w].size()); j++) {
        e[w][j] = e[w][j + 1];
      }
      e[w].pop_back();
      i--;
      st[top++] = id;
      dfs(l);
      if (l != r) dfs(r);
    }
  }
}
int sol(int uuu) {
  for (int i = 0; i < (n + 1); i++) e[i].clear(), cnt[i] = 4;
  for (int i = 0; i < (4 * n); i++) {
    int a, b, c;
    scanf("%d", &(a));
    scanf("%d %d", &(b), &(c));
    e[a].push_back((ele){i, b, c});
    bb[i] = (ele){a, b, c};
  }
  for (int i = 0; i < (n); i++) {
    sort((e[i]).begin(), (e[i]).end(), cmp);
  }
  top = 0;
  while (1) {
    int otop = top;
    for (int i = 0; i < (n + 1); i++)
      if (i) {
        dfs(i);
      }
    if (otop == top) break;
  }
  for (int i = 0; i < (n + 1); i++) e[i].clear(), cnt[i] = 4;
  if (top != 4 * n) printf("jizz0 %d\n", top);
  for (int i = 0; i < (top); i++) {
    int j = i;
    cnt[bb[st[j]].id]--;
    if (++cnt[bb[st[j]].b] == 10) puts("jizz1");
    if (++cnt[bb[st[j]].c] == 10) puts("jizz2");
  }
  puts("YES");
  for (int i = 0; i < top; i++) {
    int j = i;
    printf("%d%c", st[j] + 1, i == top - 1 ? 10 : 32);
  }
  return 1;
}
int main() {
  while (scanf("%d", &(n)) != EOF) sol(0);
  return 0;
}
