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

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

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

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

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

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

m.o = f
m.y = d
f.r = h
d.o = e
d.y = i
i.o = b
i.y = d
h.o = b
h.y = i
b.r = h
e.r = h
assert m.o.r.y.o.r.y.txt == "i"