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

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

l = A("l")
b = B("b")
j = A("j")
m = B("m")
d = B("d")
a = B("a")
g = A("g")

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

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

l = A("l")
b = B("b")
j = A("j")
m = B("m")
d = B("d")
a = B("a")
g = A("g")

l.y = g
l.q = b
b.o = l
b.z = a
j.y = g
j.q = b
m.o = g
m.z = a
d.o = g
d.z = b
a.o = g
a.z = d
g.y = l
g.q = a
assert b.o.q.o.txt == "l"