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

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

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

h = A("h")
a = B("a")
c = C("c")
i = B("i")
k = A("k")
f = C("f")
b = B("b")
e = A("e")
l = C("l")
g = B("g")

h.p = l
a.v = g
c.r = b
i.v = g
k.p = c
f.r = i
b.v = g
e.p = f
l.r = b
g.v = b
assert l.r.v.v.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

h = A("h")
a = B("a")
c = C("c")
i = B("i")
k = A("k")
f = C("f")
b = B("b")
e = A("e")
l = C("l")
g = B("g")

h.p = l
a.v = g
c.r = b
i.v = g
k.p = c
f.r = i
b.v = g
e.p = f
l.r = b
g.v = b
assert l.r.v.v.v.v.v.txt == "g"