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

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

g = A("g")
l = B("l")
f = B("f")
d = A("d")
a = A("a")
h = A("h")
j = A("j")
c = B("c")
b = A("b")

g.w = d
l.r = d
l.o = f
f.r = d
f.o = l
d.w = h
a.w = b
h.w = b
j.w = d
c.r = a
c.o = f
b.w = j
assert c.o.r.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

g = A("g")
l = B("l")
f = B("f")
d = A("d")
a = A("a")
h = A("h")
j = A("j")
c = B("c")
b = A("b")

g.w = d
l.r = d
l.o = f
f.r = d
f.o = l
d.w = h
a.w = b
h.w = b
j.w = d
c.r = a
c.o = f
b.w = j
assert c.o.r.w.w.w.w.txt == "d"