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

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

n = A("n")
h = B("h")
j = A("j")

n.s = h
h.z = j
h.x = j
j.s = h
assert n.s.z.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

n = A("n")
h = B("h")
j = A("j")

n.s = h
h.z = j
h.x = j
j.s = h
assert n.s.z.s.txt == "h"