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

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

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

n = A("n")
h = B("h")
d = C("d")
b = B("b")

n.z = b
h.s = b
h.o = n
d.q = b
d.t = n
b.s = h
b.o = n
assert b.o.z.o.z.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

n = A("n")
h = B("h")
d = C("d")
b = B("b")

n.z = b
h.s = b
h.o = n
d.q = b
d.t = n
b.s = h
b.o = n
assert b.o.z.o.z.txt == "b"