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

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

class C:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

h = A("h")
f = B("f")
b = C("b")
a = D("a")

h.t = f
f.y = b
f.w = b
b.p = h
a.o = h
assert h.t.w.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

h = A("h")
f = B("f")
b = C("b")
a = D("a")

h.t = f
f.y = b
f.w = b
b.p = h
a.o = h
assert h.t.w.p.t.txt == "f"