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

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

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

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

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

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

e.r = g
g.w = l
j.r = g
l.r = g
m.r = g
assert e.r.w.r.txt == "g"