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

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

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

h = A("h")
c = B("c")
k = C("k")
j = B("j")
e = C("e")
a = C("a")
d = A("d")
n = B("n")
b = C("b")

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

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

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

h = A("h")
c = B("c")
k = C("k")
j = B("j")
e = C("e")
a = C("a")
d = A("d")
n = B("n")
b = C("b")

h.p = k
c.u = h
c.x = h
c.p = d
k.y = e
k.r = d
j.u = h
j.p = h
j.x = h
e.y = k
e.r = d
a.y = b
a.r = d
d.p = a
n.u = h
n.p = h
n.x = h
b.y = e
b.r = h
assert k.r.p.y.txt == "b"