//Let's join Kaede Takagaki Fan Club !! #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#include //#include #include #include #include #include #include #include #include #include //#include //#include //#include //#include //#include //#include using namespace std; //using namespace atcoder; //#define int long long //#define L __int128 typedef long long ll; typedef pair P; typedef pair P1; typedef pair P2; #define pu push #define pb push_back #define eb emplace_back #define mp make_pair #define eps 1e-7 #define INF 1000000000 #define a first #define b second #define fi first #define sc second #define rng(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,x) for(int i=0;i bool chmax(t&a,u b){if(a bool chmin(t&a,u b){if(b using vc=vector; template ostream& operator<<(ostream& os,const pair& p){ return os<<"{"< ostream& operator<<(ostream& os,const vc& v){ os<<"{"; for(auto e:v)os<> 30)) * 0xbf58476d1ce4e5b9; x = (x ^ (x >> 27)) * 0x94d049bb133111eb; return x ^ (x >> 31); } size_t operator()(uint64_t x) const { static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count(); return splitmix64(x + FIXED_RANDOM); } //don't make x negative! size_t operator()(pair x)const{ return operator()(uint64_t(x.first)<<32|x.second); } }; //unordered_set -> dtype, null_type //unordered_map -> dtype(key), dtype(value) using namespace __gnu_pbds; template using hash_table=gp_hash_table; template void o(const T &a,bool space=false){ cout << a << (space?' ':'\n'); } //ios::sync_with_stdio(false); const ll mod = 998244353; //const ll mod = 1000000007; mt19937_64 mt(chrono::steady_clock::now().time_since_epoch().count()); struct modular{ ll v; modular(ll vv=0){s(vv%mod+mod);} modular& s(ll vv){ v=vv>=1; } return res; } modular inv()const{return pow(mod-2);} friend modular operator+(ll x,const modular&y){ return modular(x)+y; } friend modular operator-(ll x,const modular&y){ return modular(x)-y; } friend modular operator*(ll x,const modular&y){ return modular(x)*y; } friend modular operator/(ll x,const modular&y){ return modular(x)/y; } friend ostream& operator<<(ostream&os,const modular&m){ return os<>(istream&is,modular&m){ ll x;is>>x; m=modular(x); return is; } bool operator<(const modular&r)const{return v0){ if(n&1) res=res*x%mod; x=x*x%mod; n>>=1; } return res; } #define _sz 1 modular F[_sz],R[_sz]; void make(){ F[0] = 1; for(int i=1;i<_sz;i++) F[i] = F[i-1] * i; R[_sz-1] = F[_sz-1].pow(mod-2); for(int i=_sz-2;i>=0;i--) R[i] = R[i+1] * (i+1); } modular C(int a,int b){ if(b < 0 || a < b) return modular(); return F[a]*R[b]*R[a-b]; } /*int dst(P p, P q){ return (p.a-q.a)*(p.a-q.a)+(p.b-q.b)*(p.b-q.b); }*/ /*template void add_inplace(t &a, t b){ if(a.size() < b.size()) swap(a, b); for(int i=0;i= mod) a[i] -= mod; } return ; }*/ /*template void ov(const vc&a){ if(a.empty()) return; rep(i, a.size()) cout << a[i] << (i+1==a.size()?'\n':' '); }*/ //o(ans?"Yes":"No"); using ull=unsigned;// long long; ull _sm[256][256]; template ull nim_product(ull a, ull b, int k = 16){ if(min(a, b) <= 1) return a*b; if(!is_pre and k <= 8) return _sm[a][b]; k >>= 1; ull au = (a>>k), al = a & (((ull)1<>k), bl = b & (((ull)1<(au, bu, k); ull go2 = nim_product(al, bl, k); ull go3 = nim_product(au^al, bu^bl, k); return ((go2^go3)<(a,b,8); } constexpr int NL=150; ull dp[3*NL+5][NL+5][4], cs[NL+5][NL+5]; P pr[3*NL+5][NL+5][4]; int n,m,x,y,z; bool bad[NL+5][NL+5]; void solve(){ cin>>n>>m; cin>>x>>y>>z; x--;y--;z--; rep(i,n)bad[i][i]=true; rep(i,m){ int a,b;cin>>a>>b; a--;b--; bad[a][b]=bad[b][a]=true; } rep(i, n) rep(j, i) if(!bad[i][j]){ cs[i][j] = cs[j][i] = mt()>>48; } dp[x][1][0] = 1; rep(state, 3*n) repn(len, n) rep(mask, 4) pr[state][len][mask] = mp(-1, -1); repn(len, n){ rep(state, 3*n){ rep(mask, 4){ if(dp[state][len][mask] == 0) continue; int pre=-1, now=state; if(state>=n){ pre=state%n; if(state/n==1)now=y; else now=z; } rep(nxt, n){ if(pre == nxt or nxt == x or bad[now][nxt]) continue; if(nxt == y and (mask&1)) continue; if(nxt == z and (mask&2)) continue; int nstate = nxt, nmask = mask; if(nxt == y) nstate = n+now, nmask|=1; else if(nxt == z) nstate = n+n+now, nmask|=2; dp[nstate][len+1][nmask] ^= nim_product(dp[state][len][mask], cs[now][nxt]); auto &pp = pr[nstate][len+1][nmask]; if(pp.a < 0) pp = mp(state, mask); else{ int nxt = pp.a; if(nxt/n==1)nxt=y; else if(nxt/n==2)nxt=z; int nxt2 = state; if(nxt2/n==1)nxt2=y; else if(nxt2/n==2)nxt2=z; if(nxt > nxt2) pp = mp(state, mask); else if(nxt == nxt2 and pp.a > state) pp = mp(state, mask); } } } } rep(now, n){ if(bad[now][x]) continue; if(dp[now][len][3]){ o(len); vcans{x, now}; int M=3; while(1){ if(now == x) break; auto &pp = pr[now][len][M]; now=pp.a; len--; M=pp.b; if(now/n==1) ans.pb(y); else if(now/n==2) ans.pb(z); else ans.pb(now); } rep(i, si(ans)) cout << ++ans[i] << (i+1==si(ans)?'\n':' '); return; } } } o(-1); } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<> t; while(t--) solve(); }