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

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

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

h = A("h")
i = B("i")
c = C("c")
g = C("g")
k = B("k")
d = A("d")

h.v = c
h.r = i
i.p = g
i.u = c
c.v = d
g.v = d
k.p = g
k.u = g
d.v = c
d.r = k
assert c.v.v.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: C = None
        self.r: B = None
        self.txt = txt

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

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

h = A("h")
i = B("i")
c = C("c")
g = C("g")
k = B("k")
d = A("d")

h.v = c
h.r = i
i.p = g
i.u = c
c.v = d
g.v = d
k.p = g
k.u = g
d.v = c
d.r = k
assert c.v.v.v.r.txt == "k"