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

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

j = A("j")
m = B("m")
e = A("e")
h = B("h")
d = B("d")
f = B("f")

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

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

j = A("j")
m = B("m")
e = A("e")
h = B("h")
d = B("d")
f = B("f")

j.z = h
j.u = d
m.z = j
m.q = d
e.z = d
e.u = m
h.z = e
h.q = f
d.z = j
d.q = h
f.z = e
f.q = m
assert f.z.z.q.z.txt == "e"