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

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

c = A("c")
h = B("h")
m = B("m")
f = B("f")
g = A("g")
d = B("d")

c.p = g
c.w = g
h.o = c
h.t = d
m.o = c
m.t = d
f.o = c
f.t = m
g.p = c
g.w = c
d.o = c
d.t = m
assert g.p.p.p.p.w.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.w: A = None
        self.txt = txt

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

c = A("c")
h = B("h")
m = B("m")
f = B("f")
g = A("g")
d = B("d")

c.p = g
c.w = g
h.o = c
h.t = d
m.o = c
m.t = d
f.o = c
f.t = m
g.p = c
g.w = c
d.o = c
d.t = m
assert g.p.p.p.p.w.txt == "c"