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

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

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

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

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

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

j.y = l
l.w = d
g.y = l
d.w = l
e.y = d
assert g.y.w.w.w.w.txt == "l"