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

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

class C:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

n = A("n")
d = B("d")
f = C("f")
j = B("j")
h = C("h")

n.q = j
d.v = f
f.w = h
j.v = h
h.w = f
assert h.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

class C:
    def __init__(self, txt: str):
        self.w: C = None
        self.txt = txt

n = A("n")
d = B("d")
f = C("f")
j = B("j")
h = C("h")

n.q = j
d.v = f
f.w = h
j.v = h
h.w = f
assert h.w.w.w.txt == "f"