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

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

l = A("l")
h = B("h")
m = A("m")
f = A("f")
d = B("d")

l.s = h
l.x = d
h.y = d
m.s = d
m.x = d
f.s = h
f.x = d
d.y = h
assert f.s.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.x: B = None
        self.txt = txt

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

l = A("l")
h = B("h")
m = A("m")
f = A("f")
d = B("d")

l.s = h
l.x = d
h.y = d
m.s = d
m.x = d
f.s = h
f.x = d
d.y = h
assert f.s.y.y.txt == "h"