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

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

b = A("b")
h = B("h")
m = B("m")
a = B("a")
j = B("j")
g = A("g")

b.t = m
b.u = g
h.q = b
m.q = b
a.q = g
j.q = g
g.t = h
g.u = b
assert j.q.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.u: A = None
        self.txt = txt

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

b = A("b")
h = B("h")
m = B("m")
a = B("a")
j = B("j")
g = A("g")

b.t = m
b.u = g
h.q = b
m.q = b
a.q = g
j.q = g
g.t = h
g.u = b
assert j.q.u.u.txt == "g"