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

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

d = A("d")
n = B("n")
a = B("a")
h = A("h")

d.y = h
n.t = a
n.w = a
a.t = n
a.w = n
h.y = d
assert h.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

d = A("d")
n = B("n")
a = B("a")
h = A("h")

d.y = h
n.t = a
n.w = a
a.t = n
a.w = n
h.y = d
assert h.y.y.y.y.txt == "h"