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

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

d = A("d")
k = B("k")
c = A("c")
a = A("a")
i = B("i")
l = B("l")

d.q = a
k.y = a
k.v = l
c.q = a
a.q = d
i.y = d
i.v = k
l.y = d
l.v = k
assert i.v.v.v.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

d = A("d")
k = B("k")
c = A("c")
a = A("a")
i = B("i")
l = B("l")

d.q = a
k.y = a
k.v = l
c.q = a
a.q = d
i.y = d
i.v = k
l.y = d
l.v = k
assert i.v.v.v.y.txt == "a"