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

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

b = A("b")
f = B("f")
j = B("j")
i = A("i")
c = A("c")
a = A("a")
d = B("d")
l = A("l")

b.p = c
f.r = d
j.r = f
i.p = b
c.p = i
a.p = l
d.r = f
l.p = b
assert c.p.p.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

b = A("b")
f = B("f")
j = B("j")
i = A("i")
c = A("c")
a = A("a")
d = B("d")
l = A("l")

b.p = c
f.r = d
j.r = f
i.p = b
c.p = i
a.p = l
d.r = f
l.p = b
assert c.p.p.p.p.p.txt == "b"