Implement an algorithm to detect overlapping regions or annotations on a 2D grid.
Represent each annotation as [id, top, left, bottom, right], where rectangle boundaries are inclusive. Return every pair of IDs whose rectangles share at least one grid cell, sorted lexicographically. Implement detect_overlaps(annotations), returning a list of ID pairs; annotations have unique IDs and valid coordinates.
def detect_overlaps(annotations):