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

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

a = A("a")
f = B("f")
i = A("i")
e = B("e")
n = B("n")
c = B("c")
d = A("d")
m = A("m")
j = A("j")

a.x = n
f.r = e
f.s = n
i.x = f
e.r = c
e.s = c
n.r = c
n.s = f
c.r = f
c.s = e
d.x = c
m.x = e
j.x = e
assert j.x.r.s.r.r.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.x: B = None
        self.txt = txt

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

a = A("a")
f = B("f")
i = A("i")
e = B("e")
n = B("n")
c = B("c")
d = A("d")
m = A("m")
j = A("j")

a.x = n
f.r = e
f.s = n
i.x = f
e.r = c
e.s = c
n.r = c
n.s = f
c.r = f
c.s = e
d.x = c
m.x = e
j.x = e
assert j.x.r.s.r.r.r.s.txt == "c"