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

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

i = A("i")
h = B("h")
e = B("e")
b = A("b")
k = A("k")
f = A("f")
m = A("m")

i.r = e
h.u = e
e.u = h
b.r = h
k.r = h
f.r = e
m.r = e
assert m.r.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

i = A("i")
h = B("h")
e = B("e")
b = A("b")
k = A("k")
f = A("f")
m = A("m")

i.r = e
h.u = e
e.u = h
b.r = h
k.r = h
f.r = e
m.r = e
assert m.r.u.u.u.txt == "h"