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

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

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

m = A("m")
f = B("f")
g = C("g")

m.o = f
m.q = f
f.w = m
f.p = g
g.y = m
assert f.w.q.p.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.q: B = None
        self.txt = txt

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

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

m = A("m")
f = B("f")
g = C("g")

m.o = f
m.q = f
f.w = m
f.p = g
g.y = m
assert f.w.q.p.txt == "g"