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

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

g = A("g")
h = B("h")
m = A("m")
n = A("n")
e = B("e")
i = A("i")
j = A("j")

g.z = i
h.t = i
h.p = i
m.z = n
n.z = g
e.t = i
e.p = g
i.z = n
j.z = g
assert g.z.z.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.txt = txt

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

g = A("g")
h = B("h")
m = A("m")
n = A("n")
e = B("e")
i = A("i")
j = A("j")

g.z = i
h.t = i
h.p = i
m.z = n
n.z = g
e.t = i
e.p = g
i.z = n
j.z = g
assert g.z.z.z.z.z.z.txt == "g"