The Federations first contact with the Q came when one of them intercepted the Enterprise-D on that ships maiden voyage. Appearing in a variety of costumes, Q placed the ships senior officers on trial for the 'crimes of Humanity' - although the crew convinced Q to release them, years later he claimed that this trial was a never-ending process.
In subsequent visits Q has demonstrated a mixture of astounding power and knowledge combined with an almost childish sense of self-importance and selfishness. On his third visit to the Enterprise, Q reacted negatively to an offhand comment by Captain Jean Luc Picard; he threw the ship across thousands of light years to the system J-25, leading to first contact with the Borg and eventually to two devastating attacks by that species. He constantly berates and belittles other lifeforms and takes every oppurtunity to assert his own perfection.
During her travels in the Delta Quadrant, the USS Voyager encountered a second Q - known as Quinn - who had been imprisoned in the nucleus of a comet for political dissention against the Q. Quinn was dissatified with a life in which there was nothing left to explore to accomplish, and had sought to end his existence. Q appeared on Voyager and a hearing was held which resulted in Quinn having his abilities removed so as to allow him to lead life as a Human. Despite this offer, Quinn took his own life shortly afterwards with the help of Q.
This act apparently triggered a civil war within
the Q continuum; Q proposed to end this conflict by mating with Captain
Janeway of the USS Voyager in order to produce a new breed of Q - an offer
the Captain forcefully declined. Later the crew of Voyager where taken
to the Q continuum where, given the abilities and weapons of the Q, they
where instrumental in ending the war.