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

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

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

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

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

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

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

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

h.z = j
h.o = g
j.q = g
g.p = j
g.w = h
a.z = j
a.o = g
assert a.o.p.q.txt == "g"