fork download
  1. #include <iostream>
  2. using namespace std;
  3. void solve(){
  4. long long n;cin>>n;
  5. if(n == 2) {cout<<-1<<endl; return;}
  6. int ct = 1;
  7. for(long long i = 1 ; i <= n*n ; i+=2){
  8. cout<<i<<" ";
  9. if(ct == n) {cout<<endl; ct = 1;}
  10. else ct++;
  11. }
  12. for(long long i = 2 ; i <= n*n ; i+=2){
  13. cout<<i<<" ";
  14. if(ct == n) cout<<endl;
  15. ct++;
  16. }
  17. }
  18.  
  19. int main() {
  20. int t;cin>>t;
  21. while(t--){
  22. solve();
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0.01s 5280KB
stdin
3
1
2
3
stdout
1 
-1
1 3 5 
7 9 2 
4 6 8