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

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

n = A("n")
d = B("d")
a = A("a")
f = B("f")
b = B("b")

n.q = a
n.r = b
d.z = f
d.t = n
a.q = n
a.r = f
f.z = d
f.t = a
b.z = d
b.t = n
assert f.z.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.r: B = None
        self.txt = txt

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

n = A("n")
d = B("d")
a = A("a")
f = B("f")
b = B("b")

n.q = a
n.r = b
d.z = f
d.t = n
a.q = n
a.r = f
f.z = d
f.t = a
b.z = d
b.t = n
assert f.z.t.q.txt == "a"