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

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

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

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

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

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

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

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

m.p = i
m.r = i
i.o = f
i.q = m
i.x = g
g.x = f
f.x = g
assert m.p.o.x.txt == "g"