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

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

a = A("a")
c = B("c")
l = A("l")
b = A("b")

a.y = b
a.x = l
c.w = b
c.q = b
l.y = b
l.x = b
b.y = a
b.x = l
assert a.x.y.x.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.x: A = None
        self.txt = txt

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

a = A("a")
c = B("c")
l = A("l")
b = A("b")

a.y = b
a.x = l
c.w = b
c.q = b
l.y = b
l.x = b
b.y = a
b.x = l
assert a.x.y.x.y.txt == "b"