use khash to save p-q-table.