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

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

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

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

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

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

j.y = a
a.s = j
g.s = j
assert g.s.y.s.txt == "j"