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

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

l = A("l")
c = B("c")
f = B("f")
n = B("n")
d = A("d")
k = B("k")
m = A("m")

l.z = n
l.x = m
c.r = d
f.r = m
n.r = d
d.z = c
d.x = m
k.r = l
m.z = n
m.x = l
assert f.r.z.r.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.x: A = None
        self.txt = txt

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

l = A("l")
c = B("c")
f = B("f")
n = B("n")
d = A("d")
k = B("k")
m = A("m")

l.z = n
l.x = m
c.r = d
f.r = m
n.r = d
d.z = c
d.x = m
k.r = l
m.z = n
m.x = l
assert f.r.z.r.txt == "d"