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

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

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

b = A("b")
g = B("g")
c = C("c")
a = B("a")
n = C("n")
m = A("m")

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

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

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

b = A("b")
g = B("g")
c = C("c")
a = B("a")
n = C("n")
m = A("m")

b.q = a
g.o = b
g.q = b
g.p = b
c.x = m
a.o = m
a.q = b
a.p = b
n.x = m
m.q = a
assert g.q.q.o.txt == "m"