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

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

e = A("e")
d = B("d")
g = B("g")
n = A("n")
h = B("h")
b = B("b")
i = A("i")

e.x = n
d.p = g
d.z = g
g.p = d
g.z = h
n.x = e
h.p = g
h.z = d
b.p = h
b.z = g
i.x = e
assert e.x.x.x.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

e = A("e")
d = B("d")
g = B("g")
n = A("n")
h = B("h")
b = B("b")
i = A("i")

e.x = n
d.p = g
d.z = g
g.p = d
g.z = h
n.x = e
h.p = g
h.z = d
b.p = h
b.z = g
i.x = e
assert e.x.x.x.x.x.x.x.txt == "n"