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

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

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

b = A("b")
a = B("a")
h = C("h")
j = A("j")

b.q = h
b.p = j
a.q = j
h.u = j
h.o = b
j.q = h
j.p = b
assert a.q.p.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.p: A = None
        self.txt = txt

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

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

b = A("b")
a = B("a")
h = C("h")
j = A("j")

b.q = h
b.p = j
a.q = j
h.u = j
h.o = b
j.q = h
j.p = b
assert a.q.p.p.q.txt == "h"