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

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

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

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

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

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

j.s = f
f.v = j
f.s = n
n.s = f
d.v = n
d.s = n
assert f.s.s.v.s.txt == "f"