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

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.o: B = None
        self.txt = txt

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

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

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

class C:
    def __init__(self, txt: str):
        self.q: B = None
        self.o: B = None
        self.txt = txt

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

i.r = m
i.y = m
n.o = b
b.q = n
b.o = n
m.r = i
m.y = i
assert n.o.q.o.txt == "b"