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

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

l = A("l")
j = B("j")
f = B("f")
h = A("h")
n = A("n")
g = A("g")
d = A("d")
m = B("m")

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

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

l = A("l")
j = B("j")
f = B("f")
h = A("h")
n = A("n")
g = A("g")
d = A("d")
m = B("m")

l.x = d
l.s = f
j.s = d
f.s = d
h.x = l
h.s = j
n.x = l
n.s = f
g.x = l
g.s = m
d.x = g
d.s = j
m.s = n
assert g.s.s.s.s.x.x.x.txt == "d"