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

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

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

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

h = A("h")
c = B("c")
i = C("i")
d = D("d")
k = D("k")
n = C("n")
m = B("m")
g = B("g")

h.r = d
h.z = d
h.v = n
h.q = k
c.x = d
c.y = i
i.w = c
d.x = h
d.u = h
d.w = k
k.x = h
k.u = h
k.w = d
n.w = c
m.x = k
m.y = i
g.x = d
g.y = i
assert n.w.y.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.z: D = None
        self.v: C = None
        self.q: D = None
        self.txt = txt

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

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

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

h = A("h")
c = B("c")
i = C("i")
d = D("d")
k = D("k")
n = C("n")
m = B("m")
g = B("g")

h.r = d
h.z = d
h.v = n
h.q = k
c.x = d
c.y = i
i.w = c
d.x = h
d.u = h
d.w = k
k.x = h
k.u = h
k.w = d
n.w = c
m.x = k
m.y = i
g.x = d
g.y = i
assert n.w.y.w.x.txt == "d"