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

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

f = A("f")
e = B("e")
a = B("a")
d = B("d")
c = A("c")
i = B("i")
k = A("k")

f.t = e
f.r = a
e.x = c
e.w = a
a.x = c
a.w = e
d.x = f
d.w = a
c.t = i
c.r = e
i.x = c
i.w = d
k.t = a
k.r = a
assert f.r.x.r.w.x.r.txt == "
class A:
    def __init__(self, txt: str):
        self.t: B = None
        self.r: B = None
        self.txt = txt

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

f = A("f")
e = B("e")
a = B("a")
d = B("d")
c = A("c")
i = B("i")
k = A("k")

f.t = e
f.r = a
e.x = c
e.w = a
a.x = c
a.w = e
d.x = f
d.w = a
c.t = i
c.r = e
i.x = c
i.w = d
k.t = a
k.r = a
assert f.r.x.r.w.x.r.txt == "e"