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

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

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

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

a.x = h
a.o = j
k.p = j
k.w = a
j.r = a
j.q = a
h.r = a
h.q = a
assert a.x.r.x.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.o: C = None
        self.txt = txt

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

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

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

a.x = h
a.o = j
k.p = j
k.w = a
j.r = a
j.q = a
h.r = a
h.q = a
assert a.x.r.x.q.txt == "a"