tpjpa: fixed the query in the last part of the tp, not tested