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

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

l = A("l")
g = B("g")
h = B("h")
e = A("e")

l.z = g
l.r = e
g.w = e
h.w = e
e.z = h
e.r = l
assert e.z.w.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.r: A = None
        self.txt = txt

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

l = A("l")
g = B("g")
h = B("h")
e = A("e")

l.z = g
l.r = e
g.w = e
h.w = e
e.z = h
e.r = l
assert e.z.w.r.txt == "l"