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

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

h = A("h")
m = B("m")
e = B("e")
j = A("j")

h.s = j
m.t = j
m.z = h
e.t = j
e.z = j
j.s = h
assert j.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.txt = txt

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

h = A("h")
m = B("m")
e = B("e")
j = A("j")

h.s = j
m.t = j
m.z = h
e.t = j
e.z = j
j.s = h
assert j.s.s.s.txt == "h"