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

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

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

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

d = A("d")
e = B("e")
m = C("m")
g = D("g")
k = D("k")
j = A("j")
a = C("a")
f = C("f")
b = C("b")
i = B("i")

d.x = a
d.u = a
e.y = b
m.w = f
g.y = k
g.p = d
g.r = i
k.y = g
k.p = d
k.r = e
j.x = b
j.u = f
a.w = b
f.w = b
b.w = a
i.y = f
assert d.x.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.u: C = None
        self.txt = txt

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

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

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

d = A("d")
e = B("e")
m = C("m")
g = D("g")
k = D("k")
j = A("j")
a = C("a")
f = C("f")
b = C("b")
i = B("i")

d.x = a
d.u = a
e.y = b
m.w = f
g.y = k
g.p = d
g.r = i
k.y = g
k.p = d
k.r = e
j.x = b
j.u = f
a.w = b
f.w = b
b.w = a
i.y = f
assert d.x.w.w.w.w.txt == "a"