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

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

d = A("d")
l = B("l")
n = A("n")
h = B("h")
g = B("g")
k = B("k")

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

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

d = A("d")
l = B("l")
n = A("n")
h = B("h")
g = B("g")
k = B("k")

d.x = h
l.s = d
l.y = d
n.x = k
h.s = n
h.y = d
g.s = d
g.y = d
k.s = n
k.y = d
assert h.y.x.y.txt == "d"