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

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

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

g = A("g")
l = B("l")
d = C("d")
k = B("k")

g.y = k
g.s = l
l.o = d
l.q = d
l.z = g
d.x = k
d.r = l
k.o = d
k.q = d
k.z = g
assert k.q.r.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.s: B = None
        self.txt = txt

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

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

g = A("g")
l = B("l")
d = C("d")
k = B("k")

g.y = k
g.s = l
l.o = d
l.q = d
l.z = g
d.x = k
d.r = l
k.o = d
k.q = d
k.z = g
assert k.q.r.o.r.txt == "l"