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

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

e = A("e")
j = B("j")
m = A("m")
k = B("k")

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

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

e = A("e")
j = B("j")
m = A("m")
k = B("k")

e.r = j
j.w = k
m.r = k
k.w = j
assert j.w.w.w.w.txt == "j"