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

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

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

b = A("b")
i = B("i")
n = C("n")
g = A("g")
m = B("m")

b.o = g
i.p = m
n.y = b
g.o = b
m.p = i
assert b.o.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

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

b = A("b")
i = B("i")
n = C("n")
g = A("g")
m = B("m")

b.o = g
i.p = m
n.y = b
g.o = b
m.p = i
assert b.o.o.o.o.o.txt == "g"