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

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

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

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

c = A("c")
b = B("b")
d = C("d")
i = D("i")
n = A("n")
e = A("e")
g = B("g")

c.u = d
b.z = g
b.t = g
b.p = g
b.u = n
d.p = i
d.r = i
i.w = n
n.u = d
e.u = d
g.z = b
g.t = b
g.p = b
g.u = n
assert e.u.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.txt = txt

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

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

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

c = A("c")
b = B("b")
d = C("d")
i = D("i")
n = A("n")
e = A("e")
g = B("g")

c.u = d
b.z = g
b.t = g
b.p = g
b.u = n
d.p = i
d.r = i
i.w = n
n.u = d
e.u = d
g.z = b
g.t = b
g.p = b
g.u = n
assert e.u.p.w.txt == "n"