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

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

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

class D:
    def __init__(self, txt: str):
        self.z: B = None
        self.u: B = None
        self.q: C = None
        self.v: A = None
        self.txt = txt

h = A("h")
b = B("b")
m = C("m")
l = D("l")

h.p = m
b.w = h
m.z = l
m.t = l
m.u = b
l.z = b
l.u = b
l.q = m
l.v = h
assert h.p.u.w.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.z: B = None
        self.u: B = None
        self.q: C = None
        self.v: A = None
        self.txt = txt

h = A("h")
b = B("b")
m = C("m")
l = D("l")

h.p = m
b.w = h
m.z = l
m.t = l
m.u = b
l.z = b
l.u = b
l.q = m
l.v = h
assert h.p.u.w.p.txt == "m"