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

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

n = A("n")
f = B("f")
g = A("g")
c = B("c")
e = A("e")
m = B("m")
d = A("d")

n.r = d
n.y = m
f.v = m
f.t = n
g.r = d
g.y = m
c.v = m
c.t = g
e.r = n
e.y = c
m.v = c
m.t = e
d.r = n
d.y = c
assert f.t.y.t.r.y.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.y: B = None
        self.txt = txt

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

n = A("n")
f = B("f")
g = A("g")
c = B("c")
e = A("e")
m = B("m")
d = A("d")

n.r = d
n.y = m
f.v = m
f.t = n
g.r = d
g.y = m
c.v = m
c.t = g
e.r = n
e.y = c
m.v = c
m.t = e
d.r = n
d.y = c
assert f.t.y.t.r.y.t.txt == "e"