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

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

f = A("f")
d = B("d")
k = B("k")
g = A("g")
c = B("c")
a = B("a")

f.w = a
f.r = c
d.y = c
d.o = k
k.y = a
k.o = c
g.w = a
g.r = d
c.y = k
c.o = a
a.y = d
a.o = c
assert a.y.y.y.o.y.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.r: B = None
        self.txt = txt

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

f = A("f")
d = B("d")
k = B("k")
g = A("g")
c = B("c")
a = B("a")

f.w = a
f.r = c
d.y = c
d.o = k
k.y = a
k.o = c
g.w = a
g.r = d
c.y = k
c.o = a
a.y = d
a.o = c
assert a.y.y.y.o.y.txt == "k"