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

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

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

a.q = h
b.x = h
b.t = f
h.x = b
h.t = f
i.q = h
d.q = b
f.q = h
assert i.q.t.q.t.q.t.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

a.q = h
b.x = h
b.t = f
h.x = b
h.t = f
i.q = h
d.q = b
f.q = h
assert i.q.t.q.t.q.t.txt == "f"