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

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

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

k = A("k")
i = B("i")
b = C("b")
g = B("g")

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

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

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

k = A("k")
i = B("i")
b = C("b")
g = B("g")

k.o = b
k.q = b
i.y = k
b.r = k
g.y = k
assert g.y.q.r.o.txt == "b"