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

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

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

j = A("j")
l = B("l")
e = C("e")
d = A("d")
h = C("h")

j.w = d
j.p = d
l.q = d
e.w = j
e.v = j
e.t = l
d.w = j
d.p = j
h.w = d
h.v = j
h.t = l
assert h.w.w.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.p: A = None
        self.txt = txt

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

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

j = A("j")
l = B("l")
e = C("e")
d = A("d")
h = C("h")

j.w = d
j.p = d
l.q = d
e.w = j
e.v = j
e.t = l
d.w = j
d.p = j
h.w = d
h.v = j
h.t = l
assert h.w.w.p.w.txt == "j"