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

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

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

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

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

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

k.x = d
f.r = d
f.w = i
j.x = d
d.r = f
d.w = j
i.x = d
assert j.x.r.w.x.txt == "d"