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

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

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

g = A("g")
c = B("c")
j = C("j")
k = B("k")

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

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

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

g = A("g")
c = B("c")
j = C("j")
k = B("k")

g.z = j
g.x = j
c.y = j
c.o = g
c.x = k
j.q = g
k.y = j
k.o = g
k.x = c
assert k.y.q.z.q.txt == "g"