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

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

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

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

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

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

m.q = g
h.t = m
h.z = m
j.t = g
j.z = g
g.q = m
a.t = g
a.z = g
f.q = m
assert j.z.q.q.txt == "g"