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

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

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

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

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

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

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