Indexing and Querying Character Sets in One- and Two-Dimensional Words