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

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

a = A("a")
d = B("d")
l = A("l")
m = A("m")
k = B("k")
j = A("j")

a.w = l
a.z = d
d.o = k
d.v = k
l.w = m
l.z = d
m.w = a
m.z = k
k.o = d
k.v = d
j.w = a
j.z = k
assert m.w.z.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.z: B = None
        self.txt = txt

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

a = A("a")
d = B("d")
l = A("l")
m = A("m")
k = B("k")
j = A("j")

a.w = l
a.z = d
d.o = k
d.v = k
l.w = m
l.z = d
m.w = a
m.z = k
k.o = d
k.v = d
j.w = a
j.z = k
assert m.w.z.v.v.v.v.txt == "d"