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.s: A = None
        self.txt = txt

d = A("d")
j = B("j")
l = A("l")
f = B("f")
c = B("c")

d.y = l
d.q = f
j.q = d
j.s = l
l.y = d
l.q = j
f.q = d
f.s = d
c.q = d
c.s = l
assert l.q.s.q.s.y.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.s: A = None
        self.txt = txt

d = A("d")
j = B("j")
l = A("l")
f = B("f")
c = B("c")

d.y = l
d.q = f
j.q = d
j.s = l
l.y = d
l.q = j
f.q = d
f.s = d
c.q = d
c.s = l
assert l.q.s.q.s.y.txt == "d"