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

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

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

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

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

f.t = k
k.x = f
i.z = k
i.p = n
i.s = f
h.t = i
b.x = f
n.t = i
assert k.x.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.txt = txt

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

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

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

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

f.t = k
k.x = f
i.z = k
i.p = n
i.s = f
h.t = i
b.x = f
n.t = i
assert k.x.t.x.txt == "f"