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

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

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

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

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

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

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

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

a.r = f
a.z = f
h.q = g
f.x = a
f.o = j
g.q = h
j.r = f
j.z = f
assert g.q.q.q.txt == "h"