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

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

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

f = A("f")
h = B("h")
j = C("j")
c = B("c")
e = A("e")

f.o = h
f.z = h
h.q = c
h.r = e
h.z = j
j.v = e
c.q = h
c.r = e
c.z = j
e.o = h
e.z = c
assert j.v.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.z: B = None
        self.txt = txt

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

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

f = A("f")
h = B("h")
j = C("j")
c = B("c")
e = A("e")

f.o = h
f.z = h
h.q = c
h.r = e
h.z = j
j.v = e
c.q = h
c.r = e
c.z = j
e.o = h
e.z = c
assert j.v.z.r.txt == "e"