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

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

b = A("b")
f = B("f")
n = A("n")
c = B("c")
g = B("g")

b.z = n
b.u = n
f.q = g
n.z = b
n.u = b
c.q = f
g.q = c
assert n.u.u.z.u.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.u: A = None
        self.txt = txt

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

b = A("b")
f = B("f")
n = A("n")
c = B("c")
g = B("g")

b.z = n
b.u = n
f.q = g
n.z = b
n.u = b
c.q = f
g.q = c
assert n.u.u.z.u.z.txt == "b"