An omnipotent being with the whinsy of an imp, the temper of a child and the powers of a god, "Q" is a being to be admired and feared -- admired because he can give the crew of the U.S.S. Enterprise-D adventure and knowledge beyondtheir wildest dreams, and feared because he all too often does. Q is one of many entities who exist on a plane known as the Q Continuum. He displays unusual intrest in humanity, Captain Jean-Luc Picard in particular, and thinks nothing of meddling in Enterprise-D missions. This both annoys and frightens Picard, for although Q can impart great wisdom, he is dangerous, often mean-spirited, and always unpredictable.
The Enterprise-D first encountered Q during the Farpoint mission in 2364, when Q put humanity on trial for being "grievously savage." Q charged Picard, on pain of humanity's extinction, to prove otherwise. Picard succeeded, well enough to pique Q's curiosity so that the alie later returned, this time with a gift for Commander William Riker -- the power of a Q. Riker at first accepted the gift with good intentions, but he soon realized that absolute power was too tempting. Before Q's gift ruined his life, Riker turned the powers down.
Q later flung the Enterprise-D 7,000 light years into System J-25 where the crew encountered the Borg for the first time. Q forced Picard to admit that he needed him before saving the ship from destrucion. In 2366, as punishment for causing chaos through the universe, Q was stripped of his powers and banished from the Continuum. He fled to the Enterprise-D, where Data saved his life during an attack by Q's enemies, the Calamarain. Dat's selfless act inspired Q to act the same, thus earning him forgiveness from the Continuum.
In 2367, Q rewarded Picard and his officers for their help by casting them all in a Robin Hood fantasy designed to force Picard and Vash, once lovers, to admit their feelings ofr each other. In 2369, Q visited the Enterprise-D to evaluate Picard's new student intern who was, surprisingly, a Q. Raised as a human, Amanda Rogers didn't know her origins. Q took her home to the Continuum. Later, Q offered Picard an amazing trip back through time so that Picard could re-evaluate a rash action of his youth.
On his last visit to the Enterprise-D, Q shifted Picard through three time periods, allowing Picard to puzzle out that a strange anomaly was actually a rift in "anti-time" that would cause the destruction of all humanity. Thanks to Q's interference, Picard mended the rift and humanity's existence was secured.