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

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

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

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

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

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

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