頭を捻る
1
to puzzle over;to think deeply about;to rack one's brains over (wrack)
Other forms
頭をひねる 【あたまをひねる】