I am not that hot in SQL but here is my attempt.
The query are quite simple at the end:
CREATE TABLE A(Id int NOT NULL PRIMARY KEY)
CREATE TABLE B(Id int NOT NULL PRIMARY KEY, A int NOT NULL)
CREATE TABLE C(Id int NOT NULL PRIMARY KEY, B int NOT NULL, Closed BIT)
INSERT INTO A VALUES (1),(2),(3)
INSERT INTO B VALUES (10,1), (11,1),(12,1)
INSERT INTO B VALUES (20,2), (21,2),(22,2)
INSERT INTO C VALUES (100,10,0),(101,10,0),(102,10,0)
INSERT INTO C VALUES (110,11,0),(111,11,0),(112,11,1)
INSERT INTO C VALUES (120,12,0),(121,12,1),(122,12,1)
INSERT INTO C VALUES (200,20,1),(201,20,0),(202,20,1)
INSERT INTO C VALUES (210,21,1),(211,21,1),(212,21,1)
DELETE FROM C WHERE C.Closed = 1
DELETE FROM B
WHERE NOT EXISTS(SELECT * FROM C WHERE C.B = B.ID)
DELETE FROM B
WHERE NOT EXISTS(SELECT * FROM C WHERE C.B = B.ID AND C.Closed = 0)
DELETE FROM A
WHERE NOT EXISTS(SELECT * FROM B WHERE B.A = A.ID)
SELECT * FROM A
SELECT * FROM B
SELECT * FROM C
DROP TABLE C
DROP TABLE B
DROP TABLE A