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

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

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

j.q = m
j.z = b
n.p = j
h.p = j
b.p = j
m.q = j
m.z = n
g.p = m
assert g.p.z.p.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: B = None
        self.txt = txt

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

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

j.q = m
j.z = b
n.p = j
h.p = j
b.p = j
m.q = j
m.z = n
g.p = m
assert g.p.z.p.q.q.txt == "j"