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

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

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

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

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

f.s = h
f.w = h
h.u = d
h.p = d
h.t = b
h.x = b
d.t = h
d.x = f
b.s = d
assert d.t.x.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.w: B = None
        self.txt = txt

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

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

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

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

f.s = h
f.w = h
h.u = d
h.p = d
h.t = b
h.x = b
d.t = h
d.x = f
b.s = d
assert d.t.x.s.x.txt == "f"