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

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

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

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

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

c.w = n
c.z = n
c.q = i
n.u = c
n.x = c
n.r = k
n.y = g
i.q = c
g.s = k
g.t = e
g.r = c
e.q = c
k.u = c
k.x = c
k.r = n
k.y = g
assert k.x.z.r.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.q: C = None
        self.z: B = None
        self.txt = txt

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

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

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

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

c.w = n
c.z = n
c.q = i
n.u = c
n.x = c
n.r = k
n.y = g
i.q = c
g.s = k
g.t = e
g.r = c
e.q = c
k.u = c
k.x = c
k.r = n
k.y = g
assert k.x.z.r.x.z.txt == "n"