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

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

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

b = A("b")
k = B("k")
h = C("h")
l = B("l")
e = A("e")
m = C("m")
d = B("d")
n = A("n")
c = B("c")

b.v = k
b.u = n
b.p = n
k.w = m
k.q = n
h.r = c
h.p = m
l.w = h
l.q = e
e.v = k
e.u = b
e.p = b
m.r = k
m.p = h
d.w = m
d.q = e
n.v = l
n.u = e
n.p = b
c.w = h
c.q = b
assert k.w.r.w.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.u: A = None
        self.p: A = None
        self.txt = txt

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

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

b = A("b")
k = B("k")
h = C("h")
l = B("l")
e = A("e")
m = C("m")
d = B("d")
n = A("n")
c = B("c")

b.v = k
b.u = n
b.p = n
k.w = m
k.q = n
h.r = c
h.p = m
l.w = h
l.q = e
e.v = k
e.u = b
e.p = b
m.r = k
m.p = h
d.w = m
d.q = e
n.v = l
n.u = e
n.p = b
c.w = h
c.q = b
assert k.w.r.w.p.p.txt == "m"