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

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

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

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

n = A("n")
i = B("i")
m = C("m")
b = D("b")

n.x = b
i.t = m
m.t = b
m.x = b
m.p = i
m.w = n
b.w = n
b.v = i
assert n.x.v.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: D = None
        self.txt = txt

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

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

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

n = A("n")
i = B("i")
m = C("m")
b = D("b")

n.x = b
i.t = m
m.t = b
m.x = b
m.p = i
m.w = n
b.w = n
b.v = i
assert n.x.v.t.txt == "m"