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

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

g = A("g")
a = B("a")
k = A("k")
l = A("l")
d = B("d")

g.y = d
a.y = d
a.u = d
k.y = d
l.y = a
d.y = a
d.u = a
assert k.y.u.y.u.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

g = A("g")
a = B("a")
k = A("k")
l = A("l")
d = B("d")

g.y = d
a.y = d
a.u = d
k.y = d
l.y = a
d.y = a
d.u = a
assert k.y.u.y.u.txt == "a"