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

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

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

h.y = e
h.w = j
f.s = j
j.s = f
e.y = h
e.w = j
assert e.w.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.w: B = None
        self.txt = txt

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

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

h.y = e
h.w = j
f.s = j
j.s = f
e.y = h
e.w = j
assert e.w.s.s.txt == "j"