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

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

c = A("c")
h = B("h")
f = A("f")
e = B("e")
d = A("d")

c.q = e
h.t = d
f.q = e
e.t = c
d.q = h
assert c.q.t.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

c = A("c")
h = B("h")
f = A("f")
e = B("e")
d = A("d")

c.q = e
h.t = d
f.q = e
e.t = c
d.q = h
assert c.q.t.q.txt == "e"