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

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

c = A("c")
h = B("h")
j = A("j")
f = B("f")
l = B("l")
k = B("k")

c.r = j
h.p = f
j.r = c
f.p = k
l.p = f
k.p = l
assert f.p.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.txt = txt

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

c = A("c")
h = B("h")
j = A("j")
f = B("f")
l = B("l")
k = B("k")

c.r = j
h.p = f
j.r = c
f.p = k
l.p = f
k.p = l
assert f.p.p.p.p.p.p.txt == "f"