Disclaimer : This is maybe not the most efficient way to do it, but more something like an intuition on how to do it.
You need to replace the string A,D in the query with formula like this :
=SUBSTITUTE( textjoin(",",true,ArrayFormula(ADDRESS(1, split( textjoin(",",true,{ switch(or((ArrayFormula(regexmatch(A1:A,"Adam")))),false,,true,COLUMN(A1)), switch(or((ArrayFormula(regexmatch(B1:B,"Adam")))),false,,true,COLUMN(B1)), switch(or((ArrayFormula(regexmatch(C1:C,"Adam")))),false,,true,COLUMN(C1)), switch(or((ArrayFormula(regexmatch(D1:D,"Adam")))),false,,true,COLUMN(D1)) }) ,",",true,true) ,4))),1,) Then use it in your query like this =query( range , "Select "& (the formula) & " Where [..]")