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

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

b = A("b")
k = B("k")
j = B("j")

b.s = j
k.r = j
k.z = j
j.r = k
j.z = k
assert j.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

b = A("b")
k = B("k")
j = B("j")

b.s = j
k.r = j
k.z = j
j.r = k
j.z = k
assert j.z.z.z.txt == "k"