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

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

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

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

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

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

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

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

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

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

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