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

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

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

b = A("b")
i = B("i")
f = C("f")
g = B("g")
e = B("e")
h = A("h")

b.q = e
b.v = f
i.z = f
i.r = b
f.t = h
f.p = g
f.v = g
g.z = f
g.r = h
e.z = f
e.r = h
h.q = e
h.v = f
assert h.v.v.z.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: C = None
        self.txt = txt

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

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

b = A("b")
i = B("i")
f = C("f")
g = B("g")
e = B("e")
h = A("h")

b.q = e
b.v = f
i.z = f
i.r = b
f.t = h
f.p = g
f.v = g
g.z = f
g.r = h
e.z = f
e.r = h
h.q = e
h.v = f
assert h.v.v.z.p.z.txt == "f"