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

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

b = A("b")
k = B("k")
a = B("a")
m = B("m")
j = A("j")

b.r = a
k.z = j
k.o = j
a.z = b
a.o = b
m.z = j
m.o = j
j.r = m
assert j.r.z.r.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

b = A("b")
k = B("k")
a = B("a")
m = B("m")
j = A("j")

b.r = a
k.z = j
k.o = j
a.z = b
a.o = b
m.z = j
m.o = j
j.r = m
assert j.r.z.r.o.r.txt == "m"