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

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

k = A("k")
l = B("l")
i = B("i")
j = A("j")
h = B("h")
d = A("d")
f = B("f")

k.y = d
l.y = d
l.u = h
i.y = k
i.u = f
j.y = k
h.y = j
h.u = l
d.y = k
f.y = k
f.u = l
assert h.u.u.u.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

k = A("k")
l = B("l")
i = B("i")
j = A("j")
h = B("h")
d = A("d")
f = B("f")

k.y = d
l.y = d
l.u = h
i.y = k
i.u = f
j.y = k
h.y = j
h.u = l
d.y = k
f.y = k
f.u = l
assert h.u.u.u.y.y.txt == "k"