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

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

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

c = A("c")
e = B("e")
j = C("j")
a = C("a")
g = B("g")

c.q = j
e.q = a
e.x = c
e.z = j
j.q = a
a.q = j
g.q = a
g.x = c
g.z = j
assert g.x.q.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

c = A("c")
e = B("e")
j = C("j")
a = C("a")
g = B("g")

c.q = j
e.q = a
e.x = c
e.z = j
j.q = a
a.q = j
g.q = a
g.x = c
g.z = j
assert g.x.q.q.q.q.txt == "a"