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

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

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

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

j = A("j")
m = B("m")
h = C("h")
i = D("i")

j.s = i
j.p = h
m.s = i
h.t = j
i.x = j
assert m.s.x.p.t.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.p: C = None
        self.txt = txt

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

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

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

j = A("j")
m = B("m")
h = C("h")
i = D("i")

j.s = i
j.p = h
m.s = i
h.t = j
i.x = j
assert m.s.x.p.t.txt == "j"