class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.y: B = None
        self.txt = txt

n = A("n")
b = B("b")
d = B("d")
l = A("l")
i = A("i")
g = B("g")

n.o = i
n.z = d
b.q = g
b.y = g
d.q = g
d.y = b
l.o = n
l.z = g
i.o = l
i.z = d
g.q = d
g.y = b
assert n.o.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.z: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.q: B = None
        self.y: B = None
        self.txt = txt

n = A("n")
b = B("b")
d = B("d")
l = A("l")
i = A("i")
g = B("g")

n.o = i
n.z = d
b.q = g
b.y = g
d.q = g
d.y = b
l.o = n
l.z = g
i.o = l
i.z = d
g.q = d
g.y = b
assert n.o.z.q.txt == "g"