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

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

l = A("l")
g = B("g")
c = B("c")
f = A("f")

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

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

l = A("l")
g = B("g")
c = B("c")
f = A("f")

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