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

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

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

class D:
    def __init__(self, txt: str):
        self.t: A = None
        self.o: C = None
        self.txt = txt

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

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

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

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

class D:
    def __init__(self, txt: str):
        self.t: A = None
        self.o: C = None
        self.txt = txt

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

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