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

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

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

h = A("h")
m = B("m")
l = C("l")
i = B("i")

h.z = i
h.s = l
h.w = l
m.s = h
m.p = h
m.x = l
l.q = m
l.r = h
l.z = i
i.s = h
i.p = h
i.x = l
assert l.z.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.s: C = None
        self.w: C = None
        self.txt = txt

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

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

h = A("h")
m = B("m")
l = C("l")
i = B("i")

h.z = i
h.s = l
h.w = l
m.s = h
m.p = h
m.x = l
l.q = m
l.r = h
l.z = i
i.s = h
i.p = h
i.x = l
assert l.z.x.r.txt == "h"