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.txt = txt

k = A("k")
d = B("d")
l = A("l")
f = B("f")
e = B("e")
g = A("g")

k.q = g
d.y = k
l.q = k
f.y = g
e.y = g
g.q = k
assert d.y.q.q.q.q.q.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.txt = txt

k = A("k")
d = B("d")
l = A("l")
f = B("f")
e = B("e")
g = A("g")

k.q = g
d.y = k
l.q = k
f.y = g
e.y = g
g.q = k
assert d.y.q.q.q.q.q.txt == "g"