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

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

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

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

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

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

f.q = a
f.y = c
m.r = a
a.q = f
a.y = c
l.q = a
l.y = m
c.r = l
assert c.r.q.y.txt == "c"