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

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

e = A("e")
k = B("k")
c = B("c")
d = A("d")
j = B("j")
f = B("f")
h = A("h")

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

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

e = A("e")
k = B("k")
c = B("c")
d = A("d")
j = B("j")
f = B("f")
h = A("h")

e.y = h
e.p = f
k.w = j
c.w = j
d.y = h
d.p = c
j.w = c
f.w = c
h.y = d
h.p = j
assert h.y.p.w.w.w.txt == "j"