Language: C++

#include<iostream>
#include<string>
#include<vector>

using namespace std;

class P{
public:  
  int d,r;
};

int data,res;
vector<string>sv;

int dy[] = {-1,0,1,0};
int dx[] = {0,1,0,-1};

void input(){
  string tmp;
  sv.clear();
  for(int i = 0 ; i < 9 ; i++)cin >> tmp,sv.push_back(tmp);
}

bool check(int x,int y){
  if(!(0 <= x && x < 3))return false;
  if(!(0 <= y && y < 3))return false;
  return true;
}

void dfs(int pos,int data,vector<P>v){

  //cout << "pos = " << pos << endl;//
  //cout << "res = " << res << endl;//

  if(pos == 9){
    res++;
    return;
  }
  
  for(int i = 0 ; i < 9 ; i++){
    if(data & (1 << i))continue;
    int ndata = (data | (1 << i));
    string str = sv[i];
    for(int j = 0 ; j < 4 ; j++){
      vector<P>nv = v;
      char u,r,d,l;

      u = str[j];
      r = str[(j+1)%4];
      d = str[(j+2)%4];
      l = str[(j+3)%4];
      
      int x,y;
      x = pos%3;
      y = pos/3;
      
      int nx,ny,npos;

      // up
      ny = y + dy[0];
      nx = x + dx[0];
      if(check(nx,ny)){
        npos = ny * 3 + nx;
        if(abs(v[npos].d - u) != abs('A'- 'a'))continue;
      }

      // left
      ny = y + dy[3];
      nx = x + dx[3];
      if(check(nx,ny)){
        npos = ny * 3 + nx;
        if(abs(v[npos].r - l) != abs('A'- 'a'))continue;
      }

      P p;
      p.r = r;
      p.d = d;
      
      nv.push_back(p);
      dfs(pos+1,ndata,nv);
    }
  }
}

void solve(){
  input();
  data = 0;
  res = 0;
  vector<P>v;
  dfs(0,data,v);
  cout << res << endl;
}

int main(){
  int n;
  cin >> n;
  for(int i = 0 ; i < n ; i++)solve();
  return 0;
}

Compiler output:
a.cc: In function 'void solve()':
a.cc:87:3: error: reference to 'data' is ambiguous
   87 |   data = 0;
      |   ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:12:5: note:                 'int data'
   12 | int data,res;
      |     ^~~~
a.cc:90:9: error: reference to 'data' is ambiguous
   90 |   dfs(0,data,v);
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:12:5: note:                 'int data'
   12 | int data,res;
      |     ^~~~