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

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

l = A("l")
a = B("a")
m = A("m")
f = A("f")
k = B("k")

l.y = f
l.q = k
a.q = f
m.y = f
m.q = k
f.y = l
f.q = k
k.q = m
assert f.y.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.q: B = None
        self.txt = txt

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

l = A("l")
a = B("a")
m = A("m")
f = A("f")
k = B("k")

l.y = f
l.q = k
a.q = f
m.y = f
m.q = k
f.y = l
f.q = k
k.q = m
assert f.y.q.q.q.txt == "k"