Palindromic Queries Problem

NOt able to think of a solution