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

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

g = A("g")
k = B("k")
d = A("d")
j = A("j")
e = B("e")
m = A("m")
c = A("c")
f = A("f")

g.z = d
g.p = k
k.q = f
d.z = g
d.p = k
j.z = f
j.p = k
e.q = c
m.z = f
m.p = k
c.z = m
c.p = k
f.z = m
f.p = e
assert e.q.z.z.z.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.p: B = None
        self.txt = txt

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

g = A("g")
k = B("k")
d = A("d")
j = A("j")
e = B("e")
m = A("m")
c = A("c")
f = A("f")

g.z = d
g.p = k
k.q = f
d.z = g
d.p = k
j.z = f
j.p = k
e.q = c
m.z = f
m.p = k
c.z = m
c.p = k
f.z = m
f.p = e
assert e.q.z.z.z.z.txt == "f"