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

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

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

g.t = a
g.q = i
i.v = g
a.v = h
h.t = i
h.q = i
assert h.q.v.t.v.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.q: B = None
        self.txt = txt

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

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

g.t = a
g.q = i
i.v = g
a.v = h
h.t = i
h.q = i
assert h.q.v.t.v.txt == "h"