Elimination of Function Variables for Solving Query-Answering Problems