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

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

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

d = A("d")
a = B("a")
j = C("j")
c = C("c")
e = A("e")
h = B("h")

d.t = e
d.y = j
a.p = c
j.w = c
c.w = j
e.t = d
e.y = j
h.p = c
assert e.y.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.y: C = None
        self.txt = txt

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

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

d = A("d")
a = B("a")
j = C("j")
c = C("c")
e = A("e")
h = B("h")

d.t = e
d.y = j
a.p = c
j.w = c
c.w = j
e.t = d
e.y = j
h.p = c
assert e.y.w.w.w.txt == "c"