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

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

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

f = A("f")
e = B("e")
i = C("i")
g = C("g")

f.o = e
e.o = f
e.q = g
i.r = f
g.r = f
assert e.q.r.o.q.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.txt = txt

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

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

f = A("f")
e = B("e")
i = C("i")
g = C("g")

f.o = e
e.o = f
e.q = g
i.r = f
g.r = f
assert e.q.r.o.q.txt == "g"