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

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

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

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

f = A("f")
c = B("c")
j = C("j")
b = D("b")

f.p = c
f.u = b
c.z = b
c.x = f
c.s = f
j.z = b
j.p = c
b.t = c
assert f.u.t.s.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.u: D = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
j = C("j")
b = D("b")

f.p = c
f.u = b
c.z = b
c.x = f
c.s = f
j.z = b
j.p = c
b.t = c
assert f.u.t.s.txt == "f"