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

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

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

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

k = A("k")
j = B("j")
h = C("h")
f = D("f")

k.t = h
k.u = j
j.p = f
h.u = f
h.o = f
h.y = k
f.t = j
assert h.u.t.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.u: B = None
        self.txt = txt

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

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

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

k = A("k")
j = B("j")
h = C("h")
f = D("f")

k.t = h
k.u = j
j.p = f
h.u = f
h.o = f
h.y = k
f.t = j
assert h.u.t.p.t.txt == "j"