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

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

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

b = A("b")
c = B("c")
m = C("m")
f = A("f")
g = A("g")
j = C("j")

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

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

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

b = A("b")
c = B("c")
m = C("m")
f = A("f")
g = A("g")
j = C("j")

b.q = c
c.p = j
c.r = j
c.o = j
m.o = g
f.q = c
g.q = c
j.o = f
assert g.q.p.o.txt == "f"