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

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

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

f.t = h
f.y = i
i.q = n
i.z = h
h.t = f
h.y = n
n.q = i
n.z = h
assert f.t.t.y.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.y: B = None
        self.txt = txt

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

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

f.t = h
f.y = i
i.q = n
i.z = h
h.t = f
h.y = n
n.q = i
n.z = h
assert f.t.t.y.txt == "i"