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

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

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

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

n = A("n")
k = B("k")
c = C("c")
d = D("d")
a = D("a")

n.y = k
n.p = c
k.v = c
k.t = c
k.w = d
c.r = k
c.w = n
c.y = n
c.u = a
d.x = c
d.y = c
a.x = c
a.y = c
assert n.p.u.x.u.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.p: C = None
        self.txt = txt

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

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

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

n = A("n")
k = B("k")
c = C("c")
d = D("d")
a = D("a")

n.y = k
n.p = c
k.v = c
k.t = c
k.w = d
c.r = k
c.w = n
c.y = n
c.u = a
d.x = c
d.y = c
a.x = c
a.y = c
assert n.p.u.x.u.x.txt == "c"