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

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

c = A("c")
f = B("f")
i = B("i")
n = B("n")

c.p = i
f.o = c
f.r = c
i.o = c
i.r = c
n.o = c
n.r = c
assert f.o.p.o.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: B = None
        self.txt = txt

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

c = A("c")
f = B("f")
i = B("i")
n = B("n")

c.p = i
f.o = c
f.r = c
i.o = c
i.r = c
n.o = c
n.r = c
assert f.o.p.o.p.txt == "i"