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

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

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

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

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

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

g.y = l
g.w = m
l.u = g
h.y = l
h.w = l
m.u = h
i.u = g
assert l.u.y.u.txt == "g"