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

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

c = A("c")
m = B("m")
b = A("b")
g = B("g")
j = B("j")

c.r = b
m.o = j
m.p = b
b.r = c
g.o = j
g.p = c
j.o = g
j.p = b
assert c.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.o: B = None
        self.p: A = None
        self.txt = txt

c = A("c")
m = B("m")
b = A("b")
g = B("g")
j = B("j")

c.r = b
m.o = j
m.p = b
b.r = c
g.o = j
g.p = c
j.o = g
j.p = b
assert c.r.r.r.r.r.txt == "b"