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

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

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

m.r = h
f.p = h
k.p = g
h.r = m
b.r = h
g.r = m
assert b.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.p: A = None
        self.txt = txt

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

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