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

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

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

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

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

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

g.o = b
g.w = h
h.z = m
h.q = d
m.o = h
m.w = b
l.z = a
l.q = a
a.o = l
a.w = l
f.o = b
f.w = h
d.o = h
d.w = h
b.z = d
b.q = d
assert a.w.z.w.z.txt == "a"