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.txt = txt

h = A("h")
i = B("i")
g = B("g")
e = A("e")
m = A("m")

h.y = m
i.t = g
g.t = i
e.y = m
m.y = h
assert e.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.txt = txt

h = A("h")
i = B("i")
g = B("g")
e = A("e")
m = A("m")

h.y = m
i.t = g
g.t = i
e.y = m
m.y = h
assert e.y.y.y.y.txt == "h"