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

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

d = A("d")
f = B("f")
j = B("j")

d.w = f
f.x = d
f.s = j
j.x = d
j.s = f
assert j.s.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.txt = txt

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

d = A("d")
f = B("f")
j = B("j")

d.w = f
f.x = d
f.s = j
j.x = d
j.s = f
assert j.s.s.x.txt == "d"