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

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

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

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

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

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

j.y = g
g.x = e
e.x = g
assert g.x.x.x.txt == "e"