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

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

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

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

k = A("k")
g = B("g")
m = C("m")
e = D("e")
n = C("n")

k.w = m
g.z = e
m.p = g
m.y = k
m.r = k
e.x = k
e.u = g
e.r = g
n.p = g
n.y = k
n.r = k
assert g.z.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

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

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

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

k = A("k")
g = B("g")
m = C("m")
e = D("e")
n = C("n")

k.w = m
g.z = e
m.p = g
m.y = k
m.r = k
e.x = k
e.u = g
e.r = g
n.p = g
n.y = k
n.r = k
assert g.z.u.z.txt == "e"