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

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

e = A("e")
g = B("g")
k = B("k")
h = A("h")
d = B("d")

e.s = k
e.z = h
g.y = h
k.y = h
h.s = k
h.z = e
d.y = e
assert g.y.s.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.z: A = None
        self.txt = txt

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

e = A("e")
g = B("g")
k = B("k")
h = A("h")
d = B("d")

e.s = k
e.z = h
g.y = h
k.y = h
h.s = k
h.z = e
d.y = e
assert g.y.s.y.z.txt == "e"