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

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

m = A("m")
j = B("j")
l = B("l")
g = A("g")
h = A("h")

m.w = g
j.t = h
j.y = m
l.t = g
l.y = h
g.w = m
h.w = g
assert h.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

m = A("m")
j = B("j")
l = B("l")
g = A("g")
h = A("h")

m.w = g
j.t = h
j.y = m
l.t = g
l.y = h
g.w = m
h.w = g
assert h.w.w.w.w.w.txt == "g"