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

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

l = A("l")
m = B("m")
a = B("a")
g = B("g")
e = A("e")
c = A("c")
f = A("f")

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

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

l = A("l")
m = B("m")
a = B("a")
g = B("g")
e = A("e")
c = A("c")
f = A("f")

l.q = a
m.y = f
m.x = f
a.y = e
a.x = l
g.y = l
g.x = c
e.q = a
c.q = m
f.q = m
assert f.q.y.q.y.txt == "f"