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

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

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

g = A("g")
i = B("i")
f = C("f")
l = A("l")
n = B("n")

g.z = n
g.s = f
i.s = n
i.y = g
i.p = f
f.q = g
f.u = i
l.z = n
l.s = f
n.s = i
n.y = g
n.p = f
assert g.s.u.p.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.s: C = None
        self.txt = txt

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

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

g = A("g")
i = B("i")
f = C("f")
l = A("l")
n = B("n")

g.z = n
g.s = f
i.s = n
i.y = g
i.p = f
f.q = g
f.u = i
l.z = n
l.s = f
n.s = i
n.y = g
n.p = f
assert g.s.u.p.txt == "f"