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

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

h = A("h")
a = B("a")
i = A("i")
f = B("f")

h.q = i
a.z = f
a.s = f
i.q = h
f.z = a
f.s = a
assert f.z.s.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.txt = txt

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

h = A("h")
a = B("a")
i = A("i")
f = B("f")

h.q = i
a.z = f
a.s = f
i.q = h
f.z = a
f.s = a
assert f.z.s.z.txt == "a"