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

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

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

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

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

k.y = h
k.r = h
k.x = h
k.p = m
h.x = m
j.v = i
j.r = n
j.p = n
i.u = h
i.t = h
i.y = h
n.v = g
n.r = j
n.p = j
g.u = h
g.t = h
g.y = h
m.y = h
m.r = h
m.x = h
m.p = k
assert m.r.x.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.r: B = None
        self.p: A = None
        self.x: B = None
        self.txt = txt

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

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

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

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

k.y = h
k.r = h
k.x = h
k.p = m
h.x = m
j.v = i
j.r = n
j.p = n
i.u = h
i.t = h
i.y = h
n.v = g
n.r = j
n.p = j
g.u = h
g.t = h
g.y = h
m.y = h
m.r = h
m.x = h
m.p = k
assert m.r.x.p.p.p.txt == "k"