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

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

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

b = A("b")
g = B("g")
a = C("a")
i = A("i")
j = C("j")

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

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

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

b = A("b")
g = B("g")
a = C("a")
i = A("i")
j = C("j")

b.w = i
b.p = g
g.x = b
a.o = g
a.q = b
i.w = b
i.p = g
j.o = g
j.q = b
assert i.w.w.p.txt == "g"