diff --git a/gracedb/models.py b/gracedb/models.py
index 0fb74fc60ae38e867df62d9425b27c0e1cba3a59..ad17460d55335921a40f30eb620e518ea5ae9421 100644
--- a/gracedb/models.py
+++ b/gracedb/models.py
@@ -83,6 +83,8 @@ class Event(models.Model):
     def graceid(self):
         if self.uid:
             return self.uid
+        elif self.group.name == "Test":
+            return "T%04d" % self.id
         elif self.analysisType == "HWINJ":
             return "H%04d" % self.id
         return "G%04d" % self.id
@@ -121,13 +123,15 @@ class Event(models.Model):
 
     @classmethod
     def getByGraceid(cls, id):
-        if id[0] not in "GH":
+        if id[0] not in "GHT":
             # Very old, probably useless data.
             return cls.objects.get(uid=id)
         e = cls.objects.get(id=int(id[1:]))
-        if (id[0] == "G" and e.analysisType != "HWINJ") or (id[0]=="H" and e.analysisType =="HWINJ"):
-            return e
-        raise cls.DoesNotExist()
+        if (id[0] == "T") and (e.group.name != "Test"):
+            raise cls.DoesNotExist()
+        if (id[0] == "H") and (e.analysisType == "HWINJ"):
+            raise cls.DoesNotExist()
+        return e
 
 class EventLog(models.Model):
     class Meta:
diff --git a/gracedb/query.py b/gracedb/query.py
index 2ce6fba52b887b1882ae5ae34cf839627ff1e6d9..3d042a842d321f032074bc1dd1a75ca795a584fe 100644
--- a/gracedb/query.py
+++ b/gracedb/query.py
@@ -86,6 +86,12 @@ hidRange = hid + Suppress("..") + hid
 hidQ = Optional(Suppress(Keyword("hid:"))) + (hid^hidRange)
 hidQ = hidQ.setParseAction(maybeRange("hid", dbname="id"))
 
+# test event id
+tid = Suppress("T")+Word("0123456789")
+tidRange = tid + Suppress("..") + tid
+tidQ = Optional(Suppress(Keyword("tid:"))) + (tid^tidRange)
+tidQ = tidQ.setParseAction(maybeRange("tid", dbname="id"))
+
 # Created times
 
 nltimeRange = nltime + Suppress("..") + nltime
@@ -126,18 +132,20 @@ labelQ = (Optional(Suppress(Keyword("label:"))) + labelQ_.copy())
 labelQ.setParseAction(lambda toks: ("label", toks[0]))
 
 
-q = (gidQ | hidQ | atypeQ | groupQ | labelQ | createdQ | gpsQ).setName("query term")
+q = (gidQ | hidQ | tidQ | atypeQ | groupQ | labelQ | createdQ | gpsQ).setName("query term")
 
 def parseQuery(s):
     d={}
     for (tag, qval) in (stringStart + OneOrMore(q) + stringEnd).parseString(s).asList():
         d[tag] = d.get(tag,Q()) | qval
-    if s.find("Test") < 0:
-        # Test group is not mentioned in the query, so we exclude it.
+    if s.find("Test") < 0 and "tid" not in d:
+        # If Test group is not mentioned in the query, we exclude it.
         if "group" in d:
             d["group"] &= ~Q(group__name="Test")
         else:
             d["group"] = ~Q(group__name="Test")
+    if "tid" in d:
+        d["tid"] = d["tid"] & Q(group__name="Test")
     if "hid" in d:
         d["hid"] = d["hid"] & Q(analysisType="HWINJ")
     if "id" in d: